OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef ArrayPiece_h | 5 #include "platform/wtf/typed_arrays/ArrayPiece.h" |
6 #define ArrayPiece_h | |
7 | 6 |
8 #include "wtf/Allocator.h" | 7 // The contents of this header was moved to platform/wtf as part of |
9 #include "wtf/Forward.h" | 8 // WTF migration project. See the following post for details: |
10 #include "wtf/WTFExport.h" | 9 // https://groups.google.com/a/chromium.org/d/msg/blink-dev/tLdAZCTlcAA/bYXVT8gY
CAAJ |
11 | |
12 namespace WTF { | |
13 | |
14 // This class is for passing around un-owned bytes as a pointer + length. | |
15 // It supports implicit conversion from several other data types. | |
16 // | |
17 // ArrayPiece has the concept of being "null". This is different from an empty | |
18 // byte range. It is invalid to call methods other than isNull() on such | |
19 // instances. | |
20 // | |
21 // IMPORTANT: The data contained by ArrayPiece is NOT OWNED, so caution must be | |
22 // taken to ensure it is kept alive. | |
23 class WTF_EXPORT ArrayPiece { | |
24 DISALLOW_NEW(); | |
25 | |
26 public: | |
27 // Constructs a "null" ArrayPiece object. | |
28 ArrayPiece(); | |
29 | |
30 ArrayPiece(void* data, unsigned byteLength); | |
31 | |
32 // Constructs an ArrayPiece from the given ArrayBuffer. If the input is a | |
33 // nullptr, then the constructed instance will be isNull(). | |
34 ArrayPiece(ArrayBuffer*); | |
35 ArrayPiece(ArrayBufferView*); | |
36 | |
37 bool isNull() const; | |
38 void* data() const; | |
39 unsigned char* bytes() const; | |
40 unsigned byteLength() const; | |
41 | |
42 protected: | |
43 void initWithData(void* data, unsigned byteLength); | |
44 | |
45 private: | |
46 void initNull(); | |
47 | |
48 void* m_data; | |
49 unsigned m_byteLength; | |
50 bool m_isNull; | |
51 }; | |
52 | |
53 } // namespace WTF | |
54 | |
55 using WTF::ArrayPiece; | |
56 | |
57 #endif // ArrayPiece_h | |
OLD | NEW |