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 19 matching lines...) Expand all Loading... |
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 ReadFloat(float* result) WARN_UNUSED_RESULT; |
38 bool ReadString(std::string* result) WARN_UNUSED_RESULT; | 38 bool ReadString(std::string* result) WARN_UNUSED_RESULT; |
39 bool ReadWString(std::wstring* result) WARN_UNUSED_RESULT; | 39 bool ReadWString(std::wstring* result) WARN_UNUSED_RESULT; |
40 bool ReadString16(string16* result) WARN_UNUSED_RESULT; | 40 bool ReadString16(base::string16* result) WARN_UNUSED_RESULT; |
41 bool ReadData(const char** data, int* length) WARN_UNUSED_RESULT; | 41 bool ReadData(const char** data, int* length) WARN_UNUSED_RESULT; |
42 bool ReadBytes(const char** data, int length) WARN_UNUSED_RESULT; | 42 bool ReadBytes(const char** data, int length) WARN_UNUSED_RESULT; |
43 | 43 |
44 // Safer version of ReadInt() checks for the result not being negative. | 44 // Safer version of ReadInt() checks for the result not being negative. |
45 // Use it for reading the object sizes. | 45 // Use it for reading the object sizes. |
46 bool ReadLength(int* result) WARN_UNUSED_RESULT { | 46 bool ReadLength(int* result) WARN_UNUSED_RESULT { |
47 return ReadInt(result) && *result >= 0; | 47 return ReadInt(result) && *result >= 0; |
48 } | 48 } |
49 | 49 |
50 // Skips bytes in the read buffer and returns true if there are at least | 50 // Skips bytes in the read buffer and returns true if there are at least |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 } | 172 } |
173 bool ReadString(PickleIterator* iter, | 173 bool ReadString(PickleIterator* iter, |
174 std::string* result) const WARN_UNUSED_RESULT { | 174 std::string* result) const WARN_UNUSED_RESULT { |
175 return iter->ReadString(result); | 175 return iter->ReadString(result); |
176 } | 176 } |
177 bool ReadWString(PickleIterator* iter, | 177 bool ReadWString(PickleIterator* iter, |
178 std::wstring* result) const WARN_UNUSED_RESULT { | 178 std::wstring* result) const WARN_UNUSED_RESULT { |
179 return iter->ReadWString(result); | 179 return iter->ReadWString(result); |
180 } | 180 } |
181 bool ReadString16(PickleIterator* iter, | 181 bool ReadString16(PickleIterator* iter, |
182 string16* result) const WARN_UNUSED_RESULT { | 182 base::string16* result) const WARN_UNUSED_RESULT { |
183 return iter->ReadString16(result); | 183 return iter->ReadString16(result); |
184 } | 184 } |
185 // A pointer to the data will be placed in *data, and the length will be | 185 // A pointer to the data will be placed in *data, and the length will be |
186 // placed in *length. This buffer will be into the message's buffer so will | 186 // placed in *length. This buffer will be into the message's buffer so will |
187 // be scoped to the lifetime of the message (or until the message data is | 187 // be scoped to the lifetime of the message (or until the message data is |
188 // mutated). | 188 // mutated). |
189 bool ReadData(PickleIterator* iter, | 189 bool ReadData(PickleIterator* iter, |
190 const char** data, | 190 const char** data, |
191 int* length) const WARN_UNUSED_RESULT { | 191 int* length) const WARN_UNUSED_RESULT { |
192 return iter->ReadData(data, length); | 192 return iter->ReadData(data, length); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 return WritePOD(value); | 236 return WritePOD(value); |
237 } | 237 } |
238 bool WriteUInt64(uint64 value) { | 238 bool WriteUInt64(uint64 value) { |
239 return WritePOD(value); | 239 return WritePOD(value); |
240 } | 240 } |
241 bool WriteFloat(float value) { | 241 bool WriteFloat(float value) { |
242 return WritePOD(value); | 242 return WritePOD(value); |
243 } | 243 } |
244 bool WriteString(const std::string& value); | 244 bool WriteString(const std::string& value); |
245 bool WriteWString(const std::wstring& value); | 245 bool WriteWString(const std::wstring& value); |
246 bool WriteString16(const string16& value); | 246 bool WriteString16(const base::string16& value); |
247 // "Data" is a blob with a length. When you read it out you will be given the | 247 // "Data" is a blob with a length. When you read it out you will be given the |
248 // length. See also WriteBytes. | 248 // length. See also WriteBytes. |
249 bool WriteData(const char* data, int length); | 249 bool WriteData(const char* data, int length); |
250 // "Bytes" is a blob with no length. The caller must specify the length both | 250 // "Bytes" is a blob with no length. The caller must specify the length both |
251 // when reading and writing. It is normally used to serialize PoD types of a | 251 // when reading and writing. It is normally used to serialize PoD types of a |
252 // known size. See also WriteData. | 252 // known size. See also WriteData. |
253 bool WriteBytes(const void* data, int length); | 253 bool WriteBytes(const void* data, int length); |
254 | 254 |
255 // Reserves space for upcoming writes when multiple writes will be made and | 255 // Reserves space for upcoming writes when multiple writes will be made and |
256 // their sizes are computed in advance. It can be significantly faster to call | 256 // their sizes are computed in advance. It can be significantly faster to call |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 } | 339 } |
340 inline void WriteBytesCommon(const void* data, size_t length); | 340 inline void WriteBytesCommon(const void* data, size_t length); |
341 | 341 |
342 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); | 342 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); |
343 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); | 343 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
344 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); | 344 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
345 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); | 345 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); |
346 }; | 346 }; |
347 | 347 |
348 #endif // BASE_PICKLE_H__ | 348 #endif // BASE_PICKLE_H__ |
OLD | NEW |