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 <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
251 } | 251 } |
252 | 252 |
253 size_t capacity_after_header() const { | 253 size_t capacity_after_header() const { |
254 return capacity_after_header_; | 254 return capacity_after_header_; |
255 } | 255 } |
256 | 256 |
257 // Resize the capacity, note that the input value should not include the size | 257 // Resize the capacity, note that the input value should not include the size |
258 // of the header. | 258 // of the header. |
259 void Resize(size_t new_capacity); | 259 void Resize(size_t new_capacity); |
260 | 260 |
261 // Claims |num_bytes| bytes of payload. This is similar to Reserve in that it | |
yzshen1
2015/12/15 19:07:02
style nit: Reserve -> Reserve() and |ClaimBytes| -
| |
262 // may grow the capacity, but it also advances the write offset of the pickle | |
263 // by |num_bytes|. Claimed memory is NOT initialized, though any alignment | |
264 // padding is zeroed. | |
265 // | |
266 // Unless you're SURE you're going to write to all the allocated bytes, you | |
267 // should use |ClaimBytes| instead. | |
268 void* ClaimUninitializedBytes(size_t num_bytes); | |
269 | |
270 // Claims |num_bytes| bytes of payload, zeroing its contents. | |
271 void* ClaimBytes(size_t num_bytes); | |
272 | |
261 // Find the end of the pickled data that starts at range_start. Returns NULL | 273 // Find the end of the pickled data that starts at range_start. Returns NULL |
262 // if the entire Pickle is not found in the given data range. | 274 // if the entire Pickle is not found in the given data range. |
263 static const char* FindNext(size_t header_size, | 275 static const char* FindNext(size_t header_size, |
264 const char* range_start, | 276 const char* range_start, |
265 const char* range_end); | 277 const char* range_end); |
266 | 278 |
267 // Parse pickle header and return total size of the pickle. Data range | 279 // Parse pickle header and return total size of the pickle. Data range |
268 // doesn't need to contain entire pickle. | 280 // doesn't need to contain entire pickle. |
269 // Returns true if pickle header was found and parsed. Callers must check | 281 // Returns true if pickle header was found and parsed. Callers must check |
270 // returned |pickle_size| for sanity (against maximum message size, etc). | 282 // returned |pickle_size| for sanity (against maximum message size, etc). |
(...skipping 21 matching lines...) Expand all Loading... | |
292 size_t write_offset_; | 304 size_t write_offset_; |
293 | 305 |
294 // Just like WriteBytes, but with a compile-time size, for performance. | 306 // Just like WriteBytes, but with a compile-time size, for performance. |
295 template<size_t length> void BASE_EXPORT WriteBytesStatic(const void* data); | 307 template<size_t length> void BASE_EXPORT WriteBytesStatic(const void* data); |
296 | 308 |
297 // Writes a POD by copying its bytes. | 309 // Writes a POD by copying its bytes. |
298 template <typename T> bool WritePOD(const T& data) { | 310 template <typename T> bool WritePOD(const T& data) { |
299 WriteBytesStatic<sizeof(data)>(&data); | 311 WriteBytesStatic<sizeof(data)>(&data); |
300 return true; | 312 return true; |
301 } | 313 } |
314 | |
315 inline void* ClaimUninitializedBytesInternal(size_t num_bytes); | |
302 inline void WriteBytesCommon(const void* data, size_t length); | 316 inline void WriteBytesCommon(const void* data, size_t length); |
303 | 317 |
304 FRIEND_TEST_ALL_PREFIXES(PickleTest, DeepCopyResize); | 318 FRIEND_TEST_ALL_PREFIXES(PickleTest, DeepCopyResize); |
305 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); | 319 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); |
306 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext); | 320 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext); |
307 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow); | 321 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow); |
308 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); | 322 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
309 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); | 323 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
310 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); | 324 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); |
311 }; | 325 }; |
312 | 326 |
313 } // namespace base | 327 } // namespace base |
314 | 328 |
315 #endif // BASE_PICKLE_H_ | 329 #endif // BASE_PICKLE_H_ |
OLD | NEW |