| 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 <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // the Pickle, create a PickleIterator from a Pickle. If successful, these | 27 // the Pickle, create a PickleIterator from a Pickle. If successful, these |
| 28 // methods return true. Otherwise, false is returned to indicate that the | 28 // methods return true. Otherwise, false is returned to indicate that the |
| 29 // result could not be extracted. | 29 // result could not be extracted. |
| 30 bool ReadBool(bool* result) WARN_UNUSED_RESULT; | 30 bool ReadBool(bool* result) WARN_UNUSED_RESULT; |
| 31 bool ReadInt(int* result) WARN_UNUSED_RESULT; | 31 bool ReadInt(int* result) WARN_UNUSED_RESULT; |
| 32 bool ReadLong(long* result) WARN_UNUSED_RESULT; | 32 bool ReadLong(long* result) WARN_UNUSED_RESULT; |
| 33 bool ReadUInt16(uint16* result) WARN_UNUSED_RESULT; | 33 bool ReadUInt16(uint16* result) WARN_UNUSED_RESULT; |
| 34 bool ReadUInt32(uint32* result) WARN_UNUSED_RESULT; | 34 bool ReadUInt32(uint32* result) WARN_UNUSED_RESULT; |
| 35 bool ReadInt64(int64* result) WARN_UNUSED_RESULT; | 35 bool ReadInt64(int64* result) WARN_UNUSED_RESULT; |
| 36 bool ReadUInt64(uint64* result) WARN_UNUSED_RESULT; | 36 bool ReadUInt64(uint64* result) WARN_UNUSED_RESULT; |
| 37 bool ReadFloat(float* result) WARN_UNUSED_RESULT; |
| 37 bool ReadString(std::string* result) WARN_UNUSED_RESULT; | 38 bool ReadString(std::string* result) WARN_UNUSED_RESULT; |
| 38 bool ReadWString(std::wstring* result) WARN_UNUSED_RESULT; | 39 bool ReadWString(std::wstring* result) WARN_UNUSED_RESULT; |
| 39 bool ReadString16(string16* result) WARN_UNUSED_RESULT; | 40 bool ReadString16(string16* result) WARN_UNUSED_RESULT; |
| 40 bool ReadData(const char** data, int* length) WARN_UNUSED_RESULT; | 41 bool ReadData(const char** data, int* length) WARN_UNUSED_RESULT; |
| 41 bool ReadBytes(const char** data, int length) WARN_UNUSED_RESULT; | 42 bool ReadBytes(const char** data, int length) WARN_UNUSED_RESULT; |
| 42 | 43 |
| 43 // Safer version of ReadInt() checks for the result not being negative. | 44 // Safer version of ReadInt() checks for the result not being negative. |
| 44 // Use it for reading the object sizes. | 45 // Use it for reading the object sizes. |
| 45 bool ReadLength(int* result) WARN_UNUSED_RESULT { | 46 bool ReadLength(int* result) WARN_UNUSED_RESULT { |
| 46 return ReadInt(result) && *result >= 0; | 47 return ReadInt(result) && *result >= 0; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 } | 152 } |
| 152 bool ReadUInt32(PickleIterator* iter, uint32* result) const { | 153 bool ReadUInt32(PickleIterator* iter, uint32* result) const { |
| 153 return iter->ReadUInt32(result); | 154 return iter->ReadUInt32(result); |
| 154 } | 155 } |
| 155 bool ReadInt64(PickleIterator* iter, int64* result) const { | 156 bool ReadInt64(PickleIterator* iter, int64* result) const { |
| 156 return iter->ReadInt64(result); | 157 return iter->ReadInt64(result); |
| 157 } | 158 } |
| 158 bool ReadUInt64(PickleIterator* iter, uint64* result) const { | 159 bool ReadUInt64(PickleIterator* iter, uint64* result) const { |
| 159 return iter->ReadUInt64(result); | 160 return iter->ReadUInt64(result); |
| 160 } | 161 } |
| 162 bool ReadFloat(PickleIterator* iter, float* result) const { |
| 163 return iter->ReadFloat(result); |
| 164 } |
| 161 bool ReadString(PickleIterator* iter, std::string* result) const { | 165 bool ReadString(PickleIterator* iter, std::string* result) const { |
| 162 return iter->ReadString(result); | 166 return iter->ReadString(result); |
| 163 } | 167 } |
| 164 bool ReadWString(PickleIterator* iter, std::wstring* result) const { | 168 bool ReadWString(PickleIterator* iter, std::wstring* result) const { |
| 165 return iter->ReadWString(result); | 169 return iter->ReadWString(result); |
| 166 } | 170 } |
| 167 bool ReadString16(PickleIterator* iter, string16* result) const { | 171 bool ReadString16(PickleIterator* iter, string16* result) const { |
| 168 return iter->ReadString16(result); | 172 return iter->ReadString16(result); |
| 169 } | 173 } |
| 170 // A pointer to the data will be placed in *data, and the length will be | 174 // A pointer to the data will be placed in *data, and the length will be |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 } | 215 } |
| 212 bool WriteUInt32(uint32 value) { | 216 bool WriteUInt32(uint32 value) { |
| 213 return WriteBytes(&value, sizeof(value)); | 217 return WriteBytes(&value, sizeof(value)); |
| 214 } | 218 } |
| 215 bool WriteInt64(int64 value) { | 219 bool WriteInt64(int64 value) { |
| 216 return WriteBytes(&value, sizeof(value)); | 220 return WriteBytes(&value, sizeof(value)); |
| 217 } | 221 } |
| 218 bool WriteUInt64(uint64 value) { | 222 bool WriteUInt64(uint64 value) { |
| 219 return WriteBytes(&value, sizeof(value)); | 223 return WriteBytes(&value, sizeof(value)); |
| 220 } | 224 } |
| 225 bool WriteFloat(float value) { |
| 226 return WriteBytes(&value, sizeof(value)); |
| 227 } |
| 221 bool WriteString(const std::string& value); | 228 bool WriteString(const std::string& value); |
| 222 bool WriteWString(const std::wstring& value); | 229 bool WriteWString(const std::wstring& value); |
| 223 bool WriteString16(const string16& value); | 230 bool WriteString16(const string16& value); |
| 224 // "Data" is a blob with a length. When you read it out you will be given the | 231 // "Data" is a blob with a length. When you read it out you will be given the |
| 225 // length. See also WriteBytes. | 232 // length. See also WriteBytes. |
| 226 bool WriteData(const char* data, int length); | 233 bool WriteData(const char* data, int length); |
| 227 // "Bytes" is a blob with no length. The caller must specify the lenght both | 234 // "Bytes" is a blob with no length. The caller must specify the lenght both |
| 228 // when reading and writing. It is normally used to serialize PoD types of a | 235 // when reading and writing. It is normally used to serialize PoD types of a |
| 229 // known size. See also WriteData. | 236 // known size. See also WriteData. |
| 230 bool WriteBytes(const void* data, int data_len); | 237 bool WriteBytes(const void* data, int data_len); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 // Allocation size of payload (or -1 if allocation is const). | 341 // Allocation size of payload (or -1 if allocation is const). |
| 335 size_t capacity_; | 342 size_t capacity_; |
| 336 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. | 343 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. |
| 337 | 344 |
| 338 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); | 345 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); |
| 339 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); | 346 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
| 340 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); | 347 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
| 341 }; | 348 }; |
| 342 | 349 |
| 343 #endif // BASE_PICKLE_H__ | 350 #endif // BASE_PICKLE_H__ |
| OLD | NEW |