Chromium Code Reviews| Index: Source/wtf/ArrayBytes.h |
| diff --git a/Source/wtf/ArrayBytes.h b/Source/wtf/ArrayBytes.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..8073dac6b6d1b8416984e631691adaa5ecdae251 |
| --- /dev/null |
| +++ b/Source/wtf/ArrayBytes.h |
| @@ -0,0 +1,52 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef ArrayBytes_h |
| +#define ArrayBytes_h |
| + |
| +#include "wtf/Forward.h" |
| +#include "wtf/WTFExport.h" |
| + |
| +namespace WTF { |
| + |
| +// This class is for passing around un-owned bytes as a pointer + length. |
| +// It supports implicit conversion from several other data types. |
| +// |
| +// ArrayBytes has the concept of being "null". This is different from an empty |
| +// byte range. It is invalid to call methods other than isNull() on such |
| +// instances. |
| +// |
| +// IMPORTANT: The data contained by ArrayBytes is NOT OWNED, so caution must be |
| +// taken to ensure it is kept alive. |
| +class WTF_EXPORT ArrayBytes { |
|
abarth-chromium
2014/05/07 06:19:10
I guess we could call this an ArrayPiece after Str
eroman
2014/05/07 21:34:57
Sounds good, will make the change.
|
| +public: |
| + // Constructs a "null" ArrayBytes object. |
| + ArrayBytes(); |
| + |
| + ArrayBytes(void* data, unsigned byteLength); |
| + |
| + // Constructs an ArrayBytes from the given ArrayBuffer. If the input is a |
| + // nullptr, then the constructed instance will be isNull(). |
| + ArrayBytes(ArrayBuffer*); |
| + ArrayBytes(ArrayBufferView*); |
| + |
| + bool isNull() const; |
| + void* data() const; |
| + unsigned char* bytes() const; |
| + unsigned byteLength() const; |
| + |
| +private: |
| + void initWithData(void* data, unsigned byteLength); |
| + void initNull(); |
| + |
| + void* m_data; |
| + unsigned m_byteLength; |
| + bool m_isNull; |
|
abarth-chromium
2014/05/07 06:19:10
We can't use m_data == 0 as the m_isNull bit?
eroman
2014/05/07 21:34:57
I want to be able to distinguish between a zero-le
|
| +}; |
| + |
| +} // namespace WTF |
| + |
| +using WTF::ArrayBytes; |
| + |
| +#endif // ArrayBytes_h |