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

Side by Side Diff: src/value-serializer.h

Issue 2245753002: Blink-compatible serialization of strings. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@vs2
Patch Set: explicit cast to actually make it an unsigned comparison Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | src/value-serializer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project 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 V8_VALUE_SERIALIZER_H_ 5 #ifndef V8_VALUE_SERIALIZER_H_
6 #define V8_VALUE_SERIALIZER_H_ 6 #define V8_VALUE_SERIALIZER_H_
7 7
8 #include <cstdint> 8 #include <cstdint>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 std::vector<uint8_t> ReleaseBuffer() { return std::move(buffer_); } 52 std::vector<uint8_t> ReleaseBuffer() { return std::move(buffer_); }
53 53
54 private: 54 private:
55 // Writing the wire format. 55 // Writing the wire format.
56 void WriteTag(SerializationTag tag); 56 void WriteTag(SerializationTag tag);
57 template <typename T> 57 template <typename T>
58 void WriteVarint(T value); 58 void WriteVarint(T value);
59 template <typename T> 59 template <typename T>
60 void WriteZigZag(T value); 60 void WriteZigZag(T value);
61 void WriteDouble(double value); 61 void WriteDouble(double value);
62 void WriteOneByteString(Vector<const uint8_t> chars);
63 void WriteTwoByteString(Vector<const uc16> chars);
64 uint8_t* ReserveRawBytes(size_t bytes);
62 65
63 // Writing V8 objects of various kinds. 66 // Writing V8 objects of various kinds.
64 void WriteOddball(Oddball* oddball); 67 void WriteOddball(Oddball* oddball);
65 void WriteSmi(Smi* smi); 68 void WriteSmi(Smi* smi);
66 void WriteHeapNumber(HeapNumber* number); 69 void WriteHeapNumber(HeapNumber* number);
70 void WriteString(Handle<String> string);
67 71
68 std::vector<uint8_t> buffer_; 72 std::vector<uint8_t> buffer_;
69 73
70 DISALLOW_COPY_AND_ASSIGN(ValueSerializer); 74 DISALLOW_COPY_AND_ASSIGN(ValueSerializer);
71 }; 75 };
72 76
73 /* 77 /*
74 * Deserializes values from data written with ValueSerializer, or a compatible 78 * Deserializes values from data written with ValueSerializer, or a compatible
75 * implementation. 79 * implementation.
76 */ 80 */
77 class ValueDeserializer { 81 class ValueDeserializer {
78 public: 82 public:
79 ValueDeserializer(Isolate* isolate, Vector<const uint8_t> data); 83 ValueDeserializer(Isolate* isolate, Vector<const uint8_t> data);
80 ~ValueDeserializer(); 84 ~ValueDeserializer();
81 85
82 /* 86 /*
83 * Runs version detection logic, which may fail if the format is invalid. 87 * Runs version detection logic, which may fail if the format is invalid.
84 */ 88 */
85 Maybe<bool> ReadHeader() WARN_UNUSED_RESULT; 89 Maybe<bool> ReadHeader() WARN_UNUSED_RESULT;
86 90
87 /* 91 /*
88 * Deserializes a V8 object from the buffer. 92 * Deserializes a V8 object from the buffer.
89 */ 93 */
90 MaybeHandle<Object> ReadObject() WARN_UNUSED_RESULT; 94 MaybeHandle<Object> ReadObject() WARN_UNUSED_RESULT;
91 95
92 private: 96 private:
97 // Reading the wire format.
93 Maybe<SerializationTag> ReadTag() WARN_UNUSED_RESULT; 98 Maybe<SerializationTag> ReadTag() WARN_UNUSED_RESULT;
94 template <typename T> 99 template <typename T>
95 Maybe<T> ReadVarint() WARN_UNUSED_RESULT; 100 Maybe<T> ReadVarint() WARN_UNUSED_RESULT;
96 template <typename T> 101 template <typename T>
97 Maybe<T> ReadZigZag() WARN_UNUSED_RESULT; 102 Maybe<T> ReadZigZag() WARN_UNUSED_RESULT;
98 Maybe<double> ReadDouble() WARN_UNUSED_RESULT; 103 Maybe<double> ReadDouble() WARN_UNUSED_RESULT;
104 Maybe<Vector<const uint8_t>> ReadRawBytes(int size) WARN_UNUSED_RESULT;
105
106 // Reading V8 objects of specific kinds.
107 // The tag is assumed to have already been read.
108 MaybeHandle<String> ReadUtf8String() WARN_UNUSED_RESULT;
109 MaybeHandle<String> ReadTwoByteString() WARN_UNUSED_RESULT;
99 110
100 Isolate* const isolate_; 111 Isolate* const isolate_;
101 const uint8_t* position_; 112 const uint8_t* position_;
102 const uint8_t* const end_; 113 const uint8_t* const end_;
103 uint32_t version_ = 0; 114 uint32_t version_ = 0;
104 115
105 DISALLOW_COPY_AND_ASSIGN(ValueDeserializer); 116 DISALLOW_COPY_AND_ASSIGN(ValueDeserializer);
106 }; 117 };
107 118
108 } // namespace internal 119 } // namespace internal
109 } // namespace v8 120 } // namespace v8
110 121
111 #endif // V8_VALUE_SERIALIZER_H_ 122 #endif // V8_VALUE_SERIALIZER_H_
OLDNEW
« no previous file with comments | « no previous file | src/value-serializer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698