Chromium Code Reviews| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 // Methods for adding to the payload of the Pickle. These values are | 91 // Methods for adding to the payload of the Pickle. These values are |
| 92 // appended to the end of the Pickle's payload. When reading values from a | 92 // appended to the end of the Pickle's payload. When reading values from a |
| 93 // Pickle, it is important to read them in the order in which they were added | 93 // Pickle, it is important to read them in the order in which they were added |
| 94 // to the Pickle. | 94 // to the Pickle. |
| 95 bool WriteBool(bool value) { | 95 bool WriteBool(bool value) { |
| 96 return WriteInt(value ? 1 : 0); | 96 return WriteInt(value ? 1 : 0); |
| 97 } | 97 } |
| 98 bool WriteInt(int value) { | 98 bool WriteInt(int value) { |
| 99 return WriteBytes(&value, sizeof(value)); | 99 return WriteBytes(&value, sizeof(value)); |
| 100 } | 100 } |
| 101 // WARNING: DO NOT USE WriteLong() IF PICKLES ARE PERSISTED IN ANY WAY. | |
| 102 // WriteLong() writes whatever a "long" is on this architecture. On 32-bit | |
| 103 // platforms, it is 32 bits. On 64-bit platforms, it is 64 bits. If persisted | |
| 104 // pickles are still around after upgrading to 64-bit, or if they are copied | |
| 105 // between dissimilar systems, YOUR PICKLES WILL HAVE GONE BAD. | |
|
jar (doing other things)
2012/03/09 22:13:36
IMO, you have discovered a problem.... and it is a
Mike Mammarella
2012/03/10 00:24:42
Looks like WriteSize() might be feasible to remove
| |
| 101 bool WriteLong(long value) { | 106 bool WriteLong(long value) { |
| 102 return WriteBytes(&value, sizeof(value)); | 107 return WriteBytes(&value, sizeof(value)); |
| 103 } | 108 } |
| 109 // WARNING: SEE THE WARNING FOR WriteLong() ABOVE. USE WriteSize() CAREFULLY. | |
| 104 bool WriteSize(size_t value) { | 110 bool WriteSize(size_t value) { |
| 105 return WriteBytes(&value, sizeof(value)); | 111 return WriteBytes(&value, sizeof(value)); |
| 106 } | 112 } |
| 107 bool WriteUInt16(uint16 value) { | 113 bool WriteUInt16(uint16 value) { |
| 108 return WriteBytes(&value, sizeof(value)); | 114 return WriteBytes(&value, sizeof(value)); |
| 109 } | 115 } |
| 110 bool WriteUInt32(uint32 value) { | 116 bool WriteUInt32(uint32 value) { |
| 111 return WriteBytes(&value, sizeof(value)); | 117 return WriteBytes(&value, sizeof(value)); |
| 112 } | 118 } |
| 113 bool WriteInt64(int64 value) { | 119 bool WriteInt64(int64 value) { |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 size_t capacity_; | 249 size_t capacity_; |
| 244 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. | 250 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. |
| 245 | 251 |
| 246 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); | 252 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); |
| 247 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); | 253 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
| 248 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); | 254 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
| 249 FRIEND_TEST_ALL_PREFIXES(PickleTest, IteratorHasRoom); | 255 FRIEND_TEST_ALL_PREFIXES(PickleTest, IteratorHasRoom); |
| 250 }; | 256 }; |
| 251 | 257 |
| 252 #endif // BASE_PICKLE_H__ | 258 #endif // BASE_PICKLE_H__ |
| OLD | NEW |