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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // appended to the end of the Pickle's payload. When reading values from a | 166 // appended to the end of the Pickle's payload. When reading values from a |
167 // Pickle, it is important to read them in the order in which they were added | 167 // Pickle, it is important to read them in the order in which they were added |
168 // to the Pickle. | 168 // to the Pickle. |
169 | 169 |
170 bool WriteBool(bool value) { | 170 bool WriteBool(bool value) { |
171 return WriteInt(value ? 1 : 0); | 171 return WriteInt(value ? 1 : 0); |
172 } | 172 } |
173 bool WriteInt(int value) { | 173 bool WriteInt(int value) { |
174 return WritePOD(value); | 174 return WritePOD(value); |
175 } | 175 } |
176 // WARNING: DO NOT USE THIS METHOD IF PICKLES ARE PERSISTED IN ANY WAY. | 176 bool WriteLong(long value) { |
177 // It will write whatever a "long" is on this architecture. On 32-bit | 177 // Always write long as a 64-bit value to ensure compatibility between |
178 // platforms, it is 32 bits. On 64-bit platforms, it is 64 bits. If persisted | 178 // 32-bit and 64-bit processes. |
179 // pickles are still around after upgrading to 64-bit, or if they are copied | 179 return WritePOD(static_cast<int64_t>(value)); |
180 // between dissimilar systems, YOUR PICKLES WILL HAVE GONE BAD. | |
181 bool WriteLongUsingDangerousNonPortableLessPersistableForm(long value) { | |
182 return WritePOD(value); | |
183 } | 180 } |
184 bool WriteUInt16(uint16_t value) { return WritePOD(value); } | 181 bool WriteUInt16(uint16_t value) { return WritePOD(value); } |
185 bool WriteUInt32(uint32_t value) { return WritePOD(value); } | 182 bool WriteUInt32(uint32_t value) { return WritePOD(value); } |
186 bool WriteInt64(int64_t value) { return WritePOD(value); } | 183 bool WriteInt64(int64_t value) { return WritePOD(value); } |
187 bool WriteUInt64(uint64_t value) { return WritePOD(value); } | 184 bool WriteUInt64(uint64_t value) { return WritePOD(value); } |
188 bool WriteSizeT(size_t value) { | 185 bool WriteSizeT(size_t value) { |
189 // Always write size_t as a 64-bit value to ensure compatibility between | 186 // Always write size_t as a 64-bit value to ensure compatibility between |
190 // 32-bit and 64-bit processes. | 187 // 32-bit and 64-bit processes. |
191 return WritePOD(static_cast<uint64_t>(value)); | 188 return WritePOD(static_cast<uint64_t>(value)); |
192 } | 189 } |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext); | 313 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext); |
317 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow); | 314 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow); |
318 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); | 315 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
319 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); | 316 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
320 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); | 317 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); |
321 }; | 318 }; |
322 | 319 |
323 } // namespace base | 320 } // namespace base |
324 | 321 |
325 #endif // BASE_PICKLE_H_ | 322 #endif // BASE_PICKLE_H_ |
OLD | NEW |