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