| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 T* headerT() { | 252 T* headerT() { |
| 253 DCHECK_EQ(header_size_, sizeof(T)); | 253 DCHECK_EQ(header_size_, sizeof(T)); |
| 254 return static_cast<T*>(header_); | 254 return static_cast<T*>(header_); |
| 255 } | 255 } |
| 256 template <class T> | 256 template <class T> |
| 257 const T* headerT() const { | 257 const T* headerT() const { |
| 258 DCHECK_EQ(header_size_, sizeof(T)); | 258 DCHECK_EQ(header_size_, sizeof(T)); |
| 259 return static_cast<const T*>(header_); | 259 return static_cast<const T*>(header_); |
| 260 } | 260 } |
| 261 | 261 |
| 262 protected: | 262 // The payload is the pickle data immediately following the header. |
| 263 size_t payload_size() const { return header_->payload_size; } | 263 size_t payload_size() const { return header_->payload_size; } |
| 264 | |
| 265 char* payload() { | |
| 266 return reinterpret_cast<char*>(header_) + header_size_; | |
| 267 } | |
| 268 const char* payload() const { | 264 const char* payload() const { |
| 269 return reinterpret_cast<const char*>(header_) + header_size_; | 265 return reinterpret_cast<const char*>(header_) + header_size_; |
| 270 } | 266 } |
| 271 | 267 |
| 268 protected: |
| 269 char* payload() { |
| 270 return reinterpret_cast<char*>(header_) + header_size_; |
| 271 } |
| 272 |
| 272 // Returns the address of the byte immediately following the currently valid | 273 // Returns the address of the byte immediately following the currently valid |
| 273 // header + payload. | 274 // header + payload. |
| 274 char* end_of_payload() { | 275 char* end_of_payload() { |
| 275 // We must have a valid header_. | 276 // We must have a valid header_. |
| 276 return payload() + payload_size(); | 277 return payload() + payload_size(); |
| 277 } | 278 } |
| 278 const char* end_of_payload() const { | 279 const char* end_of_payload() const { |
| 279 // This object may be invalid. | 280 // This object may be invalid. |
| 280 return header_ ? payload() + payload_size() : NULL; | 281 return header_ ? payload() + payload_size() : NULL; |
| 281 } | 282 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 // Allocation size of payload (or -1 if allocation is const). | 324 // Allocation size of payload (or -1 if allocation is const). |
| 324 size_t capacity_; | 325 size_t capacity_; |
| 325 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. | 326 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. |
| 326 | 327 |
| 327 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); | 328 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); |
| 328 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); | 329 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
| 329 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); | 330 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
| 330 }; | 331 }; |
| 331 | 332 |
| 332 #endif // BASE_PICKLE_H__ | 333 #endif // BASE_PICKLE_H__ |
| OLD | NEW |