| 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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 bool WriteWString(const std::wstring& value); | 245 bool WriteWString(const std::wstring& value); |
| 246 bool WriteString16(const string16& value); | 246 bool WriteString16(const 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 lenght both | 250 // "Bytes" is a blob with no length. The caller must specify the lenght 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 data_len); | 253 bool WriteBytes(const void* data, int data_len); |
| 254 | 254 |
| 255 // Same as WriteData, but allows the caller to write directly into the | |
| 256 // Pickle. This saves a copy in cases where the data is not already | |
| 257 // available in a buffer. The caller should take care to not write more | |
| 258 // than the length it declares it will. Use ReadData to get the data. | |
| 259 // Returns NULL on failure. | |
| 260 // | |
| 261 // The returned pointer will only be valid until the next write operation | |
| 262 // on this Pickle. | |
| 263 char* BeginWriteData(int length); | |
| 264 | |
| 265 // For Pickles which contain variable length buffers (e.g. those created | |
| 266 // with BeginWriteData), the Pickle can | |
| 267 // be 'trimmed' if the amount of data required is less than originally | |
| 268 // requested. For example, you may have created a buffer with 10K of data, | |
| 269 // but decided to only fill 10 bytes of that data. Use this function | |
| 270 // to trim the buffer so that we don't send 9990 bytes of unused data. | |
| 271 // You cannot increase the size of the variable buffer; only shrink it. | |
| 272 // This function assumes that the length of the variable buffer has | |
| 273 // not been changed. | |
| 274 void TrimWriteData(int length); | |
| 275 | |
| 276 // 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 |
| 277 // 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 |
| 278 // Reserve() before calling WriteFoo() multiple times. | 257 // Reserve() before calling WriteFoo() multiple times. |
| 279 void Reserve(size_t additional_capacity); | 258 void Reserve(size_t additional_capacity); |
| 280 | 259 |
| 281 // Payload follows after allocation of Header (header size is customizable). | 260 // Payload follows after allocation of Header (header size is customizable). |
| 282 struct Header { | 261 struct Header { |
| 283 uint32 payload_size; // Specifies the size of the payload. | 262 uint32 payload_size; // Specifies the size of the payload. |
| 284 }; | 263 }; |
| 285 | 264 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 // The allocation granularity of the payload. | 330 // The allocation granularity of the payload. |
| 352 static const int kPayloadUnit; | 331 static const int kPayloadUnit; |
| 353 | 332 |
| 354 private: | 333 private: |
| 355 friend class PickleIterator; | 334 friend class PickleIterator; |
| 356 | 335 |
| 357 Header* header_; | 336 Header* header_; |
| 358 size_t header_size_; // Supports extra data between header and payload. | 337 size_t header_size_; // Supports extra data between header and payload. |
| 359 // Allocation size of payload (or -1 if allocation is const). | 338 // Allocation size of payload (or -1 if allocation is const). |
| 360 size_t capacity_; | 339 size_t capacity_; |
| 361 size_t variable_buffer_offset_; // IF non-zero, then offset to a buffer. | |
| 362 | 340 |
| 363 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); | 341 FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); |
| 364 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); | 342 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
| 365 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); | 343 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
| 366 }; | 344 }; |
| 367 | 345 |
| 368 #endif // BASE_PICKLE_H__ | 346 #endif // BASE_PICKLE_H__ |
| OLD | NEW |