OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 BASE_PICKLE_H_ | 5 #ifndef BASE_PICKLE_H_ |
6 #define BASE_PICKLE_H_ | 6 #define BASE_PICKLE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
102 const char* GetReadPointerAndAdvance(int num_elements, | 102 const char* GetReadPointerAndAdvance(int num_elements, |
103 size_t size_element); | 103 size_t size_element); |
104 | 104 |
105 const char* payload_; // Start of our pickle's payload. | 105 const char* payload_; // Start of our pickle's payload. |
106 size_t read_index_; // Offset of the next readable byte in payload. | 106 size_t read_index_; // Offset of the next readable byte in payload. |
107 size_t end_index_; // Payload size. | 107 size_t end_index_; // Payload size. |
108 | 108 |
109 FRIEND_TEST_ALL_PREFIXES(PickleTest, GetReadPointerAndAdvance); | 109 FRIEND_TEST_ALL_PREFIXES(PickleTest, GetReadPointerAndAdvance); |
110 }; | 110 }; |
111 | 111 |
112 // This class provides an interface analogous to base::Pickle's WriteFoo() | |
113 // methods and can be used to accurately compute the size of a hypothetical | |
114 // Pickle's payload without thinking too hard about the actual size of each | |
jam
2016/02/03 22:47:11
nit: thinking too hard->having to reference the Pi
Ken Rockot(use gerrit already)
2016/02/04 03:55:12
done
| |
115 // write operation. | |
116 class BASE_EXPORT PickleSizer { | |
117 public: | |
118 PickleSizer(); | |
119 ~PickleSizer(); | |
120 | |
121 // Returns the computed size of the payload. | |
122 size_t payload_size() const { return payload_size_; } | |
123 | |
124 void AddBool() { return AddInt(); } | |
125 void AddInt() { AddPOD<int>(); } | |
126 void AddLongUsingDangerousNonPortableLessPersistableForm() { AddPOD<long>(); } | |
127 void AddUInt16() { return AddPOD<uint16_t>(); } | |
128 void AddUInt32() { return AddPOD<uint32_t>(); } | |
129 void AddInt64() { return AddPOD<int64_t>(); } | |
130 void AddUInt64() { return AddPOD<uint64_t>(); } | |
131 void AddSizeT() { return AddPOD<uint64_t>(); } | |
132 void AddFloat() { return AddPOD<float>(); } | |
133 void AddDouble() { return AddPOD<double>(); } | |
134 void AddString(const StringPiece& value); | |
135 void AddString16(const StringPiece16& value); | |
136 void AddData(int length); | |
137 void AddBytes(int length); | |
138 | |
139 private: | |
140 // Just like AddBytes() but with a compile-time size for performance. | |
141 template<size_t length> void BASE_EXPORT AddBytesStatic(); | |
142 | |
143 template <typename T> | |
144 void AddPOD() { AddBytesStatic<sizeof(T)>(); } | |
145 | |
146 size_t payload_size_ = 0; | |
147 }; | |
148 | |
112 // This class provides facilities for basic binary value packing and unpacking. | 149 // This class provides facilities for basic binary value packing and unpacking. |
113 // | 150 // |
114 // The Pickle class supports appending primitive values (ints, strings, etc.) | 151 // The Pickle class supports appending primitive values (ints, strings, etc.) |
115 // to a pickle instance. The Pickle instance grows its internal memory buffer | 152 // to a pickle instance. The Pickle instance grows its internal memory buffer |
116 // dynamically to hold the sequence of primitive values. The internal memory | 153 // dynamically to hold the sequence of primitive values. The internal memory |
117 // buffer is exposed as the "data" of the Pickle. This "data" can be passed | 154 // buffer is exposed as the "data" of the Pickle. This "data" can be passed |
118 // to a Pickle object to initialize it for reading. | 155 // to a Pickle object to initialize it for reading. |
119 // | 156 // |
120 // When reading from a Pickle object, it is important for the consumer to know | 157 // When reading from a Pickle object, it is important for the consumer to know |
121 // what value types to read and in what order to read them as the Pickle does | 158 // what value types to read and in what order to read them as the Pickle does |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
349 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext); | 386 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext); |
350 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow); | 387 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow); |
351 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); | 388 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
352 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); | 389 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
353 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); | 390 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); |
354 }; | 391 }; |
355 | 392 |
356 } // namespace base | 393 } // namespace base |
357 | 394 |
358 #endif // BASE_PICKLE_H_ | 395 #endif // BASE_PICKLE_H_ |
OLD | NEW |