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 | |
262 // it may grow the capacity, but it also advances the write offset of the | |
263 // pickle by |num_bytes|. Claimed memory, including padding, is zeroed. | |
264 void* ClaimBytes(size_t num_bytes); | |
Lei Zhang
2015/12/16 01:46:15
Can you document the return value?
Ken Rockot(use gerrit already)
2015/12/16 01:53:41
Done
| |
265 | |
261 // Find the end of the pickled data that starts at range_start. Returns NULL | 266 // 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. | 267 // if the entire Pickle is not found in the given data range. |
263 static const char* FindNext(size_t header_size, | 268 static const char* FindNext(size_t header_size, |
264 const char* range_start, | 269 const char* range_start, |
265 const char* range_end); | 270 const char* range_end); |
266 | 271 |
267 // Parse pickle header and return total size of the pickle. Data range | 272 // Parse pickle header and return total size of the pickle. Data range |
268 // doesn't need to contain entire pickle. | 273 // doesn't need to contain entire pickle. |
269 // Returns true if pickle header was found and parsed. Callers must check | 274 // Returns true if pickle header was found and parsed. Callers must check |
270 // returned |pickle_size| for sanity (against maximum message size, etc). | 275 // returned |pickle_size| for sanity (against maximum message size, etc). |
(...skipping 21 matching lines...) Expand all Loading... | |
292 size_t write_offset_; | 297 size_t write_offset_; |
293 | 298 |
294 // Just like WriteBytes, but with a compile-time size, for performance. | 299 // Just like WriteBytes, but with a compile-time size, for performance. |
295 template<size_t length> void BASE_EXPORT WriteBytesStatic(const void* data); | 300 template<size_t length> void BASE_EXPORT WriteBytesStatic(const void* data); |
296 | 301 |
297 // Writes a POD by copying its bytes. | 302 // Writes a POD by copying its bytes. |
298 template <typename T> bool WritePOD(const T& data) { | 303 template <typename T> bool WritePOD(const T& data) { |
299 WriteBytesStatic<sizeof(data)>(&data); | 304 WriteBytesStatic<sizeof(data)>(&data); |
300 return true; | 305 return true; |
301 } | 306 } |
307 | |
308 inline void* ClaimUninitializedBytesInternal(size_t num_bytes); | |
302 inline void WriteBytesCommon(const void* data, size_t length); | 309 inline void WriteBytesCommon(const void* data, size_t length); |
303 | 310 |
304 FRIEND_TEST_ALL_PREFIXES(PickleTest, DeepCopyResize); | 311 FRIEND_TEST_ALL_PREFIXES(PickleTest, DeepCopyResize); |
305 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); | 312 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); |
306 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext); | 313 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext); |
307 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow); | 314 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow); |
308 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); | 315 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
309 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); | 316 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
310 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); | 317 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); |
311 }; | 318 }; |
312 | 319 |
313 } // namespace base | 320 } // namespace base |
314 | 321 |
315 #endif // BASE_PICKLE_H_ | 322 #endif // BASE_PICKLE_H_ |
OLD | NEW |