| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 // Payload follows after allocation of Header (header size is customizable). | 136 // Payload follows after allocation of Header (header size is customizable). |
| 137 struct Header { | 137 struct Header { |
| 138 uint32 payload_size; // Specifies the size of the payload. | 138 uint32 payload_size; // Specifies the size of the payload. |
| 139 }; | 139 }; |
| 140 | 140 |
| 141 // Returns the header, cast to a user-specified type T. The type T must be a | 141 // Returns the header, cast to a user-specified type T. The type T must be a |
| 142 // subclass of Header and its size must correspond to the header_size passed | 142 // subclass of Header and its size must correspond to the header_size passed |
| 143 // to the Pickle constructor. | 143 // to the Pickle constructor. |
| 144 template <class T> | 144 template <class T> |
| 145 T* headerT() { | 145 T* headerT() { |
| 146 DCHECK(sizeof(T) == header_size_); | 146 DCHECK_EQ(sizeof(T), header_size_); |
| 147 return static_cast<T*>(header_); | 147 return static_cast<T*>(header_); |
| 148 } | 148 } |
| 149 template <class T> | 149 template <class T> |
| 150 const T* headerT() const { | 150 const T* headerT() const { |
| 151 DCHECK(sizeof(T) == header_size_); | 151 DCHECK_EQ(sizeof(T), header_size_); |
| 152 return static_cast<const T*>(header_); | 152 return static_cast<const T*>(header_); |
| 153 } | 153 } |
| 154 | 154 |
| 155 // Returns true if the given iterator could point to data with the given | 155 // Returns true if the given iterator could point to data with the given |
| 156 // length. If there is no room for the given data before the end of the | 156 // length. If there is no room for the given data before the end of the |
| 157 // payload, returns false. | 157 // payload, returns false. |
| 158 bool IteratorHasRoomFor(const void* iter, int len) const { | 158 bool IteratorHasRoomFor(const void* iter, int len) const { |
| 159 if ((len < 0) || (iter < header_) || iter > end_of_payload()) | 159 if ((len < 0) || (iter < header_) || iter > end_of_payload()) |
| 160 return false; | 160 return false; |
| 161 const char* end_of_region = reinterpret_cast<const char*>(iter) + len; | 161 const char* end_of_region = reinterpret_cast<const char*>(iter) + len; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 size_t capacity_; | 233 size_t capacity_; |
| 234 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. | 234 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. |
| 235 | 235 |
| 236 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); | 236 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); |
| 237 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); | 237 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
| 238 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); | 238 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
| 239 FRIEND_TEST_ALL_PREFIXES(PickleTest, IteratorHasRoom); | 239 FRIEND_TEST_ALL_PREFIXES(PickleTest, IteratorHasRoom); |
| 240 }; | 240 }; |
| 241 | 241 |
| 242 #endif // BASE_PICKLE_H__ | 242 #endif // BASE_PICKLE_H__ |
| OLD | NEW |