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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // Resize the capacity, note that the input value should not include the size | 264 // Resize the capacity, note that the input value should not include the size |
265 // of the header. | 265 // of the header. |
266 void Resize(size_t new_capacity); | 266 void Resize(size_t new_capacity); |
267 | 267 |
268 // Find the end of the pickled data that starts at range_start. Returns NULL | 268 // Find the end of the pickled data that starts at range_start. Returns NULL |
269 // if the entire Pickle is not found in the given data range. | 269 // if the entire Pickle is not found in the given data range. |
270 static const char* FindNext(size_t header_size, | 270 static const char* FindNext(size_t header_size, |
271 const char* range_start, | 271 const char* range_start, |
272 const char* range_end); | 272 const char* range_end); |
273 | 273 |
| 274 // Parse pickle header and return total size of the pickle. Data range |
| 275 // doesn't need to contain entire pickle. |
| 276 // Returns true if pickle header was found and parsed. Callers must check |
| 277 // returned |pickle_size| for sanity (against maximum message size, etc). |
| 278 // NOTE: when function successfully parses a header, but encounters an |
| 279 // overflow during pickle size calculation, it sets |pickle_size| to the |
| 280 // maximum size_t value and returns true. |
| 281 static bool PeekNext(size_t header_size, |
| 282 const char* range_start, |
| 283 const char* range_end, |
| 284 size_t* pickle_size); |
| 285 |
274 // The allocation granularity of the payload. | 286 // The allocation granularity of the payload. |
275 static const int kPayloadUnit; | 287 static const int kPayloadUnit; |
276 | 288 |
277 private: | 289 private: |
278 friend class PickleIterator; | 290 friend class PickleIterator; |
279 | 291 |
280 Header* header_; | 292 Header* header_; |
281 size_t header_size_; // Supports extra data between header and payload. | 293 size_t header_size_; // Supports extra data between header and payload. |
282 // Allocation size of payload (or -1 if allocation is const). Note: this | 294 // Allocation size of payload (or -1 if allocation is const). Note: this |
283 // doesn't count the header. | 295 // doesn't count the header. |
284 size_t capacity_after_header_; | 296 size_t capacity_after_header_; |
285 // The offset at which we will write the next field. Note: this doesn't count | 297 // The offset at which we will write the next field. Note: this doesn't count |
286 // the header. | 298 // the header. |
287 size_t write_offset_; | 299 size_t write_offset_; |
288 | 300 |
289 // Just like WriteBytes, but with a compile-time size, for performance. | 301 // Just like WriteBytes, but with a compile-time size, for performance. |
290 template<size_t length> void BASE_EXPORT WriteBytesStatic(const void* data); | 302 template<size_t length> void BASE_EXPORT WriteBytesStatic(const void* data); |
291 | 303 |
292 // Writes a POD by copying its bytes. | 304 // Writes a POD by copying its bytes. |
293 template <typename T> bool WritePOD(const T& data) { | 305 template <typename T> bool WritePOD(const T& data) { |
294 WriteBytesStatic<sizeof(data)>(&data); | 306 WriteBytesStatic<sizeof(data)>(&data); |
295 return true; | 307 return true; |
296 } | 308 } |
297 inline void WriteBytesCommon(const void* data, size_t length); | 309 inline void WriteBytesCommon(const void* data, size_t length); |
298 | 310 |
299 FRIEND_TEST_ALL_PREFIXES(PickleTest, DeepCopyResize); | 311 FRIEND_TEST_ALL_PREFIXES(PickleTest, DeepCopyResize); |
300 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); | 312 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); |
| 313 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext); |
| 314 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow); |
301 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); | 315 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
302 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); | 316 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
303 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); | 317 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); |
304 }; | 318 }; |
305 | 319 |
306 } // namespace base | 320 } // namespace base |
307 | 321 |
308 #endif // BASE_PICKLE_H_ | 322 #endif // BASE_PICKLE_H_ |
OLD | NEW |