| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 return ReadInt(result) && *result >= 0; | 67 return ReadInt(result) && *result >= 0; |
| 68 } | 68 } |
| 69 | 69 |
| 70 // Skips bytes in the read buffer and returns true if there are at least | 70 // Skips bytes in the read buffer and returns true if there are at least |
| 71 // num_bytes available. Otherwise, does nothing and returns false. | 71 // num_bytes available. Otherwise, does nothing and returns false. |
| 72 bool SkipBytes(int num_bytes) WARN_UNUSED_RESULT { | 72 bool SkipBytes(int num_bytes) WARN_UNUSED_RESULT { |
| 73 return !!GetReadPointerAndAdvance(num_bytes); | 73 return !!GetReadPointerAndAdvance(num_bytes); |
| 74 } | 74 } |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 // Aligns 'i' by rounding it up to the next multiple of 'alignment'. | |
| 78 static size_t AlignInt(size_t i, int alignment) { | |
| 79 return i + (alignment - (i % alignment)) % alignment; | |
| 80 } | |
| 81 | |
| 82 // Read Type from Pickle. | 77 // Read Type from Pickle. |
| 83 template <typename Type> | 78 template <typename Type> |
| 84 bool ReadBuiltinType(Type* result); | 79 bool ReadBuiltinType(Type* result); |
| 85 | 80 |
| 86 // Advance read_index_ but do not allow it to exceed end_index_. | 81 // Advance read_index_ but do not allow it to exceed end_index_. |
| 87 // Keeps read_index_ aligned. | 82 // Keeps read_index_ aligned. |
| 88 void Advance(size_t size); | 83 void Advance(size_t size); |
| 89 | 84 |
| 90 // Get read pointer for Type and advance read pointer. | 85 // Get read pointer for Type and advance read pointer. |
| 91 template<typename Type> | 86 template<typename Type> |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 263 } | 258 } |
| 264 | 259 |
| 265 size_t capacity_after_header() const { | 260 size_t capacity_after_header() const { |
| 266 return capacity_after_header_; | 261 return capacity_after_header_; |
| 267 } | 262 } |
| 268 | 263 |
| 269 // 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 |
| 270 // of the header. | 265 // of the header. |
| 271 void Resize(size_t new_capacity); | 266 void Resize(size_t new_capacity); |
| 272 | 267 |
| 273 // Aligns 'i' by rounding it up to the next multiple of 'alignment' | |
| 274 static size_t AlignInt(size_t i, int alignment) { | |
| 275 return i + (alignment - (i % alignment)) % alignment; | |
| 276 } | |
| 277 | |
| 278 // 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 |
| 279 // 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. |
| 280 static const char* FindNext(size_t header_size, | 270 static const char* FindNext(size_t header_size, |
| 281 const char* range_start, | 271 const char* range_start, |
| 282 const char* range_end); | 272 const char* range_end); |
| 283 | 273 |
| 284 // The allocation granularity of the payload. | 274 // The allocation granularity of the payload. |
| 285 static const int kPayloadUnit; | 275 static const int kPayloadUnit; |
| 286 | 276 |
| 287 private: | 277 private: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 308 | 298 |
| 309 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); | 299 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); |
| 310 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); | 300 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
| 311 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); | 301 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
| 312 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); | 302 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); |
| 313 }; | 303 }; |
| 314 | 304 |
| 315 } // namespace base | 305 } // namespace base |
| 316 | 306 |
| 317 #endif // BASE_PICKLE_H_ | 307 #endif // BASE_PICKLE_H_ |
| OLD | NEW |