OLD | NEW |
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 Loading... |
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_ |
OLD | NEW |