OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 const void* data() const { return header_; } | 60 const void* data() const { return header_; } |
61 | 61 |
62 // Methods for reading the payload of the Pickle. To read from the start of | 62 // Methods for reading the payload of the Pickle. To read from the start of |
63 // the Pickle, initialize *iter to NULL. If successful, these methods return | 63 // the Pickle, initialize *iter to NULL. If successful, these methods return |
64 // true. Otherwise, false is returned to indicate that the result could not | 64 // true. Otherwise, false is returned to indicate that the result could not |
65 // be extracted. | 65 // be extracted. |
66 bool ReadBool(void** iter, bool* result) const; | 66 bool ReadBool(void** iter, bool* result) const; |
67 bool ReadInt(void** iter, int* result) const; | 67 bool ReadInt(void** iter, int* result) const; |
68 bool ReadLong(void** iter, long* result) const; | 68 bool ReadLong(void** iter, long* result) const; |
69 bool ReadSize(void** iter, size_t* result) const; | 69 bool ReadSize(void** iter, size_t* result) const; |
| 70 bool ReadUInt32(void** iter, uint32* result) const; |
70 bool ReadInt64(void** iter, int64* result) const; | 71 bool ReadInt64(void** iter, int64* result) const; |
71 bool ReadIntPtr(void** iter, intptr_t* result) const; | 72 bool ReadIntPtr(void** iter, intptr_t* result) const; |
72 bool ReadString(void** iter, std::string* result) const; | 73 bool ReadString(void** iter, std::string* result) const; |
73 bool ReadWString(void** iter, std::wstring* result) const; | 74 bool ReadWString(void** iter, std::wstring* result) const; |
74 bool ReadData(void** iter, const char** data, int* length) const; | 75 bool ReadData(void** iter, const char** data, int* length) const; |
75 bool ReadBytes(void** iter, const char** data, int length) const; | 76 bool ReadBytes(void** iter, const char** data, int length) const; |
76 | 77 |
77 // Safer version of ReadInt() checks for the result not being negative. | 78 // Safer version of ReadInt() checks for the result not being negative. |
78 // Use it for reading the object sizes. | 79 // Use it for reading the object sizes. |
79 bool ReadLength(void** iter, int* result) const; | 80 bool ReadLength(void** iter, int* result) const; |
80 | 81 |
81 // Methods for adding to the payload of the Pickle. These values are | 82 // Methods for adding to the payload of the Pickle. These values are |
82 // appended to the end of the Pickle's payload. When reading values from a | 83 // appended to the end of the Pickle's payload. When reading values from a |
83 // Pickle, it is important to read them in the order in which they were added | 84 // Pickle, it is important to read them in the order in which they were added |
84 // to the Pickle. | 85 // to the Pickle. |
85 bool WriteBool(bool value) { | 86 bool WriteBool(bool value) { |
86 return WriteInt(value ? 1 : 0); | 87 return WriteInt(value ? 1 : 0); |
87 } | 88 } |
88 bool WriteInt(int value) { | 89 bool WriteInt(int value) { |
89 return WriteBytes(&value, sizeof(value)); | 90 return WriteBytes(&value, sizeof(value)); |
90 } | 91 } |
91 bool WriteLong(long value) { | 92 bool WriteLong(long value) { |
92 return WriteBytes(&value, sizeof(value)); | 93 return WriteBytes(&value, sizeof(value)); |
93 } | 94 } |
94 bool WriteSize(size_t value) { | 95 bool WriteSize(size_t value) { |
95 return WriteBytes(&value, sizeof(value)); | 96 return WriteBytes(&value, sizeof(value)); |
96 } | 97 } |
| 98 bool WriteUInt32(uint32 value) { |
| 99 return WriteBytes(&value, sizeof(value)); |
| 100 } |
97 bool WriteInt64(int64 value) { | 101 bool WriteInt64(int64 value) { |
98 return WriteBytes(&value, sizeof(value)); | 102 return WriteBytes(&value, sizeof(value)); |
99 } | 103 } |
100 bool WriteIntPtr(intptr_t value) { | 104 bool WriteIntPtr(intptr_t value) { |
101 return WriteBytes(&value, sizeof(value)); | 105 return WriteBytes(&value, sizeof(value)); |
102 } | 106 } |
103 bool WriteString(const std::string& value); | 107 bool WriteString(const std::string& value); |
104 bool WriteWString(const std::wstring& value); | 108 bool WriteWString(const std::wstring& value); |
105 bool WriteData(const char* data, int length); | 109 bool WriteData(const char* data, int length); |
106 bool WriteBytes(const void* data, int data_len); | 110 bool WriteBytes(const void* data, int data_len); |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 size_t capacity_; | 228 size_t capacity_; |
225 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. | 229 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. |
226 | 230 |
227 FRIEND_TEST(PickleTest, Resize); | 231 FRIEND_TEST(PickleTest, Resize); |
228 FRIEND_TEST(PickleTest, FindNext); | 232 FRIEND_TEST(PickleTest, FindNext); |
229 FRIEND_TEST(PickleTest, IteratorHasRoom); | 233 FRIEND_TEST(PickleTest, IteratorHasRoom); |
230 }; | 234 }; |
231 | 235 |
232 #endif // BASE_PICKLE_H__ | 236 #endif // BASE_PICKLE_H__ |
233 | 237 |
OLD | NEW |