Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2138)

Unified Diff: Source/wtf/ArrayPiece.h

Issue 267133002: [webcrypto] Allow both ArrayBuffer and ArrayBufferView as inputs to crypto.subtle methods. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rename ArrayBytes --> ArrayPiece Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/crypto/SubtleCrypto.idl ('k') | Source/wtf/ArrayPiece.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/wtf/ArrayPiece.h
diff --git a/Source/wtf/ArrayPiece.h b/Source/wtf/ArrayPiece.h
new file mode 100644
index 0000000000000000000000000000000000000000..b4af6b423f1aacbf6cc13aa64ad6eb2100098239
--- /dev/null
+++ b/Source/wtf/ArrayPiece.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 ArrayPiece_h
+#define ArrayPiece_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.
+//
+// ArrayPiece 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 ArrayPiece is NOT OWNED, so caution must be
+// taken to ensure it is kept alive.
+class WTF_EXPORT ArrayPiece {
+public:
+ // Constructs a "null" ArrayPiece object.
+ ArrayPiece();
+
+ ArrayPiece(void* data, unsigned byteLength);
+
+ // Constructs an ArrayPiece from the given ArrayBuffer. If the input is a
+ // nullptr, then the constructed instance will be isNull().
+ ArrayPiece(ArrayBuffer*);
+ ArrayPiece(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;
+};
+
+} // namespace WTF
+
+using WTF::ArrayPiece;
+
+#endif // ArrayPiece_h
« no previous file with comments | « Source/modules/crypto/SubtleCrypto.idl ('k') | Source/wtf/ArrayPiece.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698