Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: base/pickle.h

Issue 10667002: Make the serialization of IPC::Messages inside other IPC::Messages independent (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ipc/ipc.gyp » ('j') | ipc/ipc_message.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 161 }
162 bool ReadString(PickleIterator* iter, std::string* result) const { 162 bool ReadString(PickleIterator* iter, std::string* result) const {
163 return iter->ReadString(result); 163 return iter->ReadString(result);
164 } 164 }
165 bool ReadWString(PickleIterator* iter, std::wstring* result) const { 165 bool ReadWString(PickleIterator* iter, std::wstring* result) const {
166 return iter->ReadWString(result); 166 return iter->ReadWString(result);
167 } 167 }
168 bool ReadString16(PickleIterator* iter, string16* result) const { 168 bool ReadString16(PickleIterator* iter, string16* result) const {
169 return iter->ReadString16(result); 169 return iter->ReadString16(result);
170 } 170 }
171 // A pointer to the data will be placed in *data, and the length will be
172 // placed in *length. This buffer will be into the message's buffer so will
173 // be scoped to the lifetime of the message (or until the message data is
174 // mutated).
171 bool ReadData(PickleIterator* iter, const char** data, int* length) const { 175 bool ReadData(PickleIterator* iter, const char** data, int* length) const {
172 return iter->ReadData(data, length); 176 return iter->ReadData(data, length);
173 } 177 }
178 // A pointer to the data will be placed in *data. The caller specifies the
179 // number of bytes to read, and ReadBytes will validate this length. The
180 // returned buffer will be into the message's buffer so will be scoped to the
181 // lifetime of the message (or until the message data is mutated).
174 bool ReadBytes(PickleIterator* iter, const char** data, int length) const { 182 bool ReadBytes(PickleIterator* iter, const char** data, int length) const {
175 return iter->ReadBytes(data, length); 183 return iter->ReadBytes(data, length);
176 } 184 }
177 185
178 // Safer version of ReadInt() checks for the result not being negative. 186 // Safer version of ReadInt() checks for the result not being negative.
179 // Use it for reading the object sizes. 187 // Use it for reading the object sizes.
180 bool ReadLength(PickleIterator* iter, int* result) const { 188 bool ReadLength(PickleIterator* iter, int* result) const {
181 return iter->ReadLength(result); 189 return iter->ReadLength(result);
182 } 190 }
183 191
(...skipping 23 matching lines...) Expand all
207 } 215 }
208 bool WriteInt64(int64 value) { 216 bool WriteInt64(int64 value) {
209 return WriteBytes(&value, sizeof(value)); 217 return WriteBytes(&value, sizeof(value));
210 } 218 }
211 bool WriteUInt64(uint64 value) { 219 bool WriteUInt64(uint64 value) {
212 return WriteBytes(&value, sizeof(value)); 220 return WriteBytes(&value, sizeof(value));
213 } 221 }
214 bool WriteString(const std::string& value); 222 bool WriteString(const std::string& value);
215 bool WriteWString(const std::wstring& value); 223 bool WriteWString(const std::wstring& value);
216 bool WriteString16(const string16& value); 224 bool WriteString16(const string16& value);
225 // "Data" is a blob with a length. When you read it out you will be given the
226 // length. See also WriteBytes.
217 bool WriteData(const char* data, int length); 227 bool WriteData(const char* data, int length);
228 // "Bytes" is a blob with no length. The caller must specify the lenght both
229 // when reading and writing. It is normally used to serialize PoD types of a
230 // known size. See also WriteData.
218 bool WriteBytes(const void* data, int data_len); 231 bool WriteBytes(const void* data, int data_len);
219 232
220 // Same as WriteData, but allows the caller to write directly into the 233 // Same as WriteData, but allows the caller to write directly into the
221 // Pickle. This saves a copy in cases where the data is not already 234 // Pickle. This saves a copy in cases where the data is not already
222 // available in a buffer. The caller should take care to not write more 235 // available in a buffer. The caller should take care to not write more
223 // than the length it declares it will. Use ReadData to get the data. 236 // than the length it declares it will. Use ReadData to get the data.
224 // Returns NULL on failure. 237 // Returns NULL on failure.
225 // 238 //
226 // The returned pointer will only be valid until the next write operation 239 // The returned pointer will only be valid until the next write operation
227 // on this Pickle. 240 // on this Pickle.
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 // Allocation size of payload (or -1 if allocation is const). 335 // Allocation size of payload (or -1 if allocation is const).
323 size_t capacity_; 336 size_t capacity_;
324 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. 337 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer.
325 338
326 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); 339 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize);
327 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); 340 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext);
328 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); 341 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader);
329 }; 342 };
330 343
331 #endif // BASE_PICKLE_H__ 344 #endif // BASE_PICKLE_H__
OLDNEW
« no previous file with comments | « no previous file | ipc/ipc.gyp » ('j') | ipc/ipc_message.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698