[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 4 | |
tfarina | a3116351 | 2015-05-13 22:10:15 | [diff] [blame^] | 5 | #ifndef BASE_PICKLE_H_ |
| 6 | #define BASE_PICKLE_H_ |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 10 | #include "base/base_export.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 11 | #include "base/basictypes.h" |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 12 | #include "base/compiler_specific.h" |
[email protected] | a918f87 | 2010-06-01 14:30:51 | [diff] [blame] | 13 | #include "base/gtest_prod_util.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 14 | #include "base/logging.h" |
[email protected] | d529cb0 | 2013-06-10 19:06:57 | [diff] [blame] | 15 | #include "base/strings/string16.h" |
brucedawson | eaa3896 | 2015-03-10 01:46:50 | [diff] [blame] | 16 | #include "base/strings/string_piece.h" |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 17 | |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 18 | class Pickle; |
| 19 | |
| 20 | // PickleIterator reads data from a Pickle. The Pickle object must remain valid |
| 21 | // while the PickleIterator object is in use. |
| 22 | class BASE_EXPORT PickleIterator { |
| 23 | public: |
[email protected] | a15016f | 2014-06-02 23:23:49 | [diff] [blame] | 24 | PickleIterator() : payload_(NULL), read_index_(0), end_index_(0) {} |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 25 | explicit PickleIterator(const Pickle& pickle); |
| 26 | |
| 27 | // Methods for reading the payload of the Pickle. To read from the start of |
| 28 | // the Pickle, create a PickleIterator from a Pickle. If successful, these |
| 29 | // methods return true. Otherwise, false is returned to indicate that the |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 30 | // result could not be extracted. It is not possible to read from the iterator |
[email protected] | a15016f | 2014-06-02 23:23:49 | [diff] [blame] | 31 | // after that. |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 32 | bool ReadBool(bool* result) WARN_UNUSED_RESULT; |
| 33 | bool ReadInt(int* result) WARN_UNUSED_RESULT; |
| 34 | bool ReadLong(long* result) WARN_UNUSED_RESULT; |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 35 | bool ReadUInt16(uint16* result) WARN_UNUSED_RESULT; |
| 36 | bool ReadUInt32(uint32* result) WARN_UNUSED_RESULT; |
| 37 | bool ReadInt64(int64* result) WARN_UNUSED_RESULT; |
| 38 | bool ReadUInt64(uint64* result) WARN_UNUSED_RESULT; |
pkasting | 89a19f14 | 2014-10-02 03:01:04 | [diff] [blame] | 39 | bool ReadSizeT(size_t* result) WARN_UNUSED_RESULT; |
[email protected] | b1f61b03 | 2012-11-28 15:40:58 | [diff] [blame] | 40 | bool ReadFloat(float* result) WARN_UNUSED_RESULT; |
[email protected] | 915cc7d | 2014-07-14 22:50:32 | [diff] [blame] | 41 | bool ReadDouble(double* result) WARN_UNUSED_RESULT; |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 42 | bool ReadString(std::string* result) WARN_UNUSED_RESULT; |
brucedawson | eaa3896 | 2015-03-10 01:46:50 | [diff] [blame] | 43 | // The StringPiece data will only be valid for the lifetime of the message. |
| 44 | bool ReadStringPiece(base::StringPiece* result) WARN_UNUSED_RESULT; |
[email protected] | 476dafb | 2013-12-03 00:39:26 | [diff] [blame] | 45 | bool ReadString16(base::string16* result) WARN_UNUSED_RESULT; |
brucedawson | eaa3896 | 2015-03-10 01:46:50 | [diff] [blame] | 46 | // The StringPiece16 data will only be valid for the lifetime of the message. |
| 47 | bool ReadStringPiece16(base::StringPiece16* result) WARN_UNUSED_RESULT; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 48 | |
| 49 | // A pointer to the data will be placed in |*data|, and the length will be |
| 50 | // placed in |*length|. The pointer placed into |*data| points into the |
| 51 | // message's buffer so it will be scoped to the lifetime of the message (or |
| 52 | // until the message data is mutated). Do not keep the pointer around! |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 53 | bool ReadData(const char** data, int* length) WARN_UNUSED_RESULT; |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 54 | |
| 55 | // A pointer to the data will be placed in |*data|. The caller specifies the |
| 56 | // number of bytes to read, and ReadBytes will validate this length. The |
| 57 | // pointer placed into |*data| points into the message's buffer so it will be |
| 58 | // scoped to the lifetime of the message (or until the message data is |
| 59 | // mutated). Do not keep the pointer around! |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 60 | bool ReadBytes(const char** data, int length) WARN_UNUSED_RESULT; |
| 61 | |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 62 | // A safer version of ReadInt() that checks for the result not being negative. |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 63 | // Use it for reading the object sizes. |
| 64 | bool ReadLength(int* result) WARN_UNUSED_RESULT { |
| 65 | return ReadInt(result) && *result >= 0; |
| 66 | } |
| 67 | |
| 68 | // Skips bytes in the read buffer and returns true if there are at least |
| 69 | // num_bytes available. Otherwise, does nothing and returns false. |
| 70 | bool SkipBytes(int num_bytes) WARN_UNUSED_RESULT { |
| 71 | return !!GetReadPointerAndAdvance(num_bytes); |
| 72 | } |
| 73 | |
| 74 | private: |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 75 | // Aligns 'i' by rounding it up to the next multiple of 'alignment'. |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 76 | static size_t AlignInt(size_t i, int alignment) { |
| 77 | return i + (alignment - (i % alignment)) % alignment; |
| 78 | } |
| 79 | |
| 80 | // Read Type from Pickle. |
| 81 | template <typename Type> |
[email protected] | a15016f | 2014-06-02 23:23:49 | [diff] [blame] | 82 | bool ReadBuiltinType(Type* result); |
| 83 | |
| 84 | // Advance read_index_ but do not allow it to exceed end_index_. |
| 85 | // Keeps read_index_ aligned. |
| 86 | void Advance(size_t size); |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 87 | |
| 88 | // Get read pointer for Type and advance read pointer. |
| 89 | template<typename Type> |
[email protected] | a15016f | 2014-06-02 23:23:49 | [diff] [blame] | 90 | const char* GetReadPointerAndAdvance(); |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 91 | |
| 92 | // Get read pointer for |num_bytes| and advance read pointer. This method |
| 93 | // checks num_bytes for negativity and wrapping. |
| 94 | const char* GetReadPointerAndAdvance(int num_bytes); |
| 95 | |
| 96 | // Get read pointer for (num_elements * size_element) bytes and advance read |
| 97 | // pointer. This method checks for int overflow, negativity and wrapping. |
[email protected] | a15016f | 2014-06-02 23:23:49 | [diff] [blame] | 98 | const char* GetReadPointerAndAdvance(int num_elements, |
| 99 | size_t size_element); |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 100 | |
[email protected] | a15016f | 2014-06-02 23:23:49 | [diff] [blame] | 101 | const char* payload_; // Start of our pickle's payload. |
| 102 | size_t read_index_; // Offset of the next readable byte in payload. |
| 103 | size_t end_index_; // Payload size. |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 104 | |
| 105 | FRIEND_TEST_ALL_PREFIXES(PickleTest, GetReadPointerAndAdvance); |
| 106 | }; |
| 107 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 108 | // This class provides facilities for basic binary value packing and unpacking. |
| 109 | // |
| 110 | // The Pickle class supports appending primitive values (ints, strings, etc.) |
| 111 | // to a pickle instance. The Pickle instance grows its internal memory buffer |
| 112 | // dynamically to hold the sequence of primitive values. The internal memory |
| 113 | // buffer is exposed as the "data" of the Pickle. This "data" can be passed |
| 114 | // to a Pickle object to initialize it for reading. |
| 115 | // |
| 116 | // When reading from a Pickle object, it is important for the consumer to know |
| 117 | // what value types to read and in what order to read them as the Pickle does |
| 118 | // not keep track of the type of data written to it. |
| 119 | // |
| 120 | // The Pickle's data has a header which contains the size of the Pickle's |
| 121 | // payload. It can optionally support additional space in the header. That |
| 122 | // space is controlled by the header_size parameter passed to the Pickle |
| 123 | // constructor. |
| 124 | // |
[email protected] | 0bea725 | 2011-08-05 15:34:00 | [diff] [blame] | 125 | class BASE_EXPORT Pickle { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 126 | public: |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 127 | // Initialize a Pickle object using the default header size. |
| 128 | Pickle(); |
| 129 | |
| 130 | // Initialize a Pickle object with the specified header size in bytes, which |
| 131 | // must be greater-than-or-equal-to sizeof(Pickle::Header). The header size |
| 132 | // will be rounded up to ensure that the header size is 32bit-aligned. |
| 133 | explicit Pickle(int header_size); |
| 134 | |
| 135 | // Initializes a Pickle from a const block of data. The data is not copied; |
| 136 | // instead the data is merely referenced by this Pickle. Only const methods |
| 137 | // should be used on the Pickle when initialized this way. The header |
| 138 | // padding size is deduced from the data length. |
[email protected] | 753bb25 | 2013-11-04 22:28:12 | [diff] [blame] | 139 | Pickle(const char* data, int data_len); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 140 | |
| 141 | // Initializes a Pickle as a deep copy of another Pickle. |
| 142 | Pickle(const Pickle& other); |
| 143 | |
[email protected] | f60c32b | 2011-09-25 03:08:13 | [diff] [blame] | 144 | // Note: There are no virtual methods in this class. This destructor is |
| 145 | // virtual as an element of defensive coding. Other classes have derived from |
| 146 | // this class, and there is a *chance* that they will cast into this base |
| 147 | // class before destruction. At least one such class does have a virtual |
| 148 | // destructor, suggesting at least some need to call more derived destructors. |
[email protected] | a502bbe7 | 2011-01-07 18:06:45 | [diff] [blame] | 149 | virtual ~Pickle(); |
| 150 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 151 | // Performs a deep copy. |
| 152 | Pickle& operator=(const Pickle& other); |
| 153 | |
| 154 | // Returns the size of the Pickle's data. |
[email protected] | 8a86140 | 2011-01-28 19:59:11 | [diff] [blame] | 155 | size_t size() const { return header_size_ + header_->payload_size; } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 156 | |
| 157 | // Returns the data for this Pickle. |
| 158 | const void* data() const { return header_; } |
| 159 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 160 | // Methods for adding to the payload of the Pickle. These values are |
| 161 | // appended to the end of the Pickle's payload. When reading values from a |
| 162 | // Pickle, it is important to read them in the order in which they were added |
| 163 | // to the Pickle. |
avi | 48fc13b | 2014-12-28 23:31:48 | [diff] [blame] | 164 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 165 | bool WriteBool(bool value) { |
| 166 | return WriteInt(value ? 1 : 0); |
| 167 | } |
| 168 | bool WriteInt(int value) { |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 169 | return WritePOD(value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 170 | } |
[email protected] | c272d08 | 2012-03-23 00:03:10 | [diff] [blame] | 171 | // WARNING: DO NOT USE THIS METHOD IF PICKLES ARE PERSISTED IN ANY WAY. |
| 172 | // It will write whatever a "long" is on this architecture. On 32-bit |
| 173 | // platforms, it is 32 bits. On 64-bit platforms, it is 64 bits. If persisted |
| 174 | // pickles are still around after upgrading to 64-bit, or if they are copied |
| 175 | // between dissimilar systems, YOUR PICKLES WILL HAVE GONE BAD. |
| 176 | bool WriteLongUsingDangerousNonPortableLessPersistableForm(long value) { |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 177 | return WritePOD(value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 178 | } |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 179 | bool WriteUInt16(uint16 value) { |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 180 | return WritePOD(value); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 181 | } |
[email protected] | 48ce616a | 2008-12-29 18:55:18 | [diff] [blame] | 182 | bool WriteUInt32(uint32 value) { |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 183 | return WritePOD(value); |
[email protected] | 48ce616a | 2008-12-29 18:55:18 | [diff] [blame] | 184 | } |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 185 | bool WriteInt64(int64 value) { |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 186 | return WritePOD(value); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 187 | } |
[email protected] | b7a5d99 | 2009-10-28 04:21:01 | [diff] [blame] | 188 | bool WriteUInt64(uint64 value) { |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 189 | return WritePOD(value); |
[email protected] | b7a5d99 | 2009-10-28 04:21:01 | [diff] [blame] | 190 | } |
pkasting | 89a19f14 | 2014-10-02 03:01:04 | [diff] [blame] | 191 | bool WriteSizeT(size_t value) { |
| 192 | // Always write size_t as a 64-bit value to ensure compatibility between |
| 193 | // 32-bit and 64-bit processes. |
| 194 | return WritePOD(static_cast<uint64>(value)); |
| 195 | } |
[email protected] | b1f61b03 | 2012-11-28 15:40:58 | [diff] [blame] | 196 | bool WriteFloat(float value) { |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 197 | return WritePOD(value); |
[email protected] | b1f61b03 | 2012-11-28 15:40:58 | [diff] [blame] | 198 | } |
[email protected] | 915cc7d | 2014-07-14 22:50:32 | [diff] [blame] | 199 | bool WriteDouble(double value) { |
| 200 | return WritePOD(value); |
| 201 | } |
brucedawson | eaa3896 | 2015-03-10 01:46:50 | [diff] [blame] | 202 | bool WriteString(const base::StringPiece& value); |
brucedawson | eaa3896 | 2015-03-10 01:46:50 | [diff] [blame] | 203 | bool WriteString16(const base::StringPiece16& value); |
[email protected] | 34d4861 | 2012-06-29 00:05:04 | [diff] [blame] | 204 | // "Data" is a blob with a length. When you read it out you will be given the |
| 205 | // length. See also WriteBytes. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 206 | bool WriteData(const char* data, int length); |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 207 | // "Bytes" is a blob with no length. The caller must specify the length both |
[email protected] | 34d4861 | 2012-06-29 00:05:04 | [diff] [blame] | 208 | // when reading and writing. It is normally used to serialize PoD types of a |
| 209 | // known size. See also WriteData. |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 210 | bool WriteBytes(const void* data, int length); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 211 | |
[email protected] | 032bfc4 | 2013-10-29 22:23:52 | [diff] [blame] | 212 | // Reserves space for upcoming writes when multiple writes will be made and |
| 213 | // their sizes are computed in advance. It can be significantly faster to call |
| 214 | // Reserve() before calling WriteFoo() multiple times. |
| 215 | void Reserve(size_t additional_capacity); |
| 216 | |
[email protected] | c9046af | 2008-08-06 20:35:17 | [diff] [blame] | 217 | // Payload follows after allocation of Header (header size is customizable). |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 218 | struct Header { |
[email protected] | c9046af | 2008-08-06 20:35:17 | [diff] [blame] | 219 | uint32 payload_size; // Specifies the size of the payload. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 220 | }; |
| 221 | |
| 222 | // Returns the header, cast to a user-specified type T. The type T must be a |
| 223 | // subclass of Header and its size must correspond to the header_size passed |
| 224 | // to the Pickle constructor. |
| 225 | template <class T> |
| 226 | T* headerT() { |
[email protected] | 5d2b449 | 2011-03-01 02:48:05 | [diff] [blame] | 227 | DCHECK_EQ(header_size_, sizeof(T)); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 228 | return static_cast<T*>(header_); |
| 229 | } |
| 230 | template <class T> |
| 231 | const T* headerT() const { |
[email protected] | 5d2b449 | 2011-03-01 02:48:05 | [diff] [blame] | 232 | DCHECK_EQ(header_size_, sizeof(T)); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 233 | return static_cast<const T*>(header_); |
| 234 | } |
| 235 | |
[email protected] | 73d96dc | 2012-03-30 22:35:27 | [diff] [blame] | 236 | // The payload is the pickle data immediately following the header. |
[email protected] | a15016f | 2014-06-02 23:23:49 | [diff] [blame] | 237 | size_t payload_size() const { |
| 238 | return header_ ? header_->payload_size : 0; |
| 239 | } |
[email protected] | e00a6c0a | 2013-01-18 18:20:57 | [diff] [blame] | 240 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 241 | const char* payload() const { |
| 242 | return reinterpret_cast<const char*>(header_) + header_size_; |
| 243 | } |
| 244 | |
| 245 | // Returns the address of the byte immediately following the currently valid |
| 246 | // header + payload. |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 247 | const char* end_of_payload() const { |
[email protected] | d87f8e6f | 2010-11-15 19:31:23 | [diff] [blame] | 248 | // This object may be invalid. |
| 249 | return header_ ? payload() + payload_size() : NULL; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 250 | } |
| 251 | |
[email protected] | e00a6c0a | 2013-01-18 18:20:57 | [diff] [blame] | 252 | protected: |
| 253 | char* mutable_payload() { |
| 254 | return reinterpret_cast<char*>(header_) + header_size_; |
| 255 | } |
| 256 | |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 257 | size_t capacity_after_header() const { |
| 258 | return capacity_after_header_; |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 259 | } |
| 260 | |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 261 | // Resize the capacity, note that the input value should not include the size |
| 262 | // of the header. |
| 263 | void Resize(size_t new_capacity); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 264 | |
| 265 | // Aligns 'i' by rounding it up to the next multiple of 'alignment' |
[email protected] | c9046af | 2008-08-06 20:35:17 | [diff] [blame] | 266 | static size_t AlignInt(size_t i, int alignment) { |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 267 | return i + (alignment - (i % alignment)) % alignment; |
| 268 | } |
| 269 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 270 | // Find the end of the pickled data that starts at range_start. Returns NULL |
| 271 | // if the entire Pickle is not found in the given data range. |
| 272 | static const char* FindNext(size_t header_size, |
| 273 | const char* range_start, |
| 274 | const char* range_end); |
| 275 | |
| 276 | // The allocation granularity of the payload. |
| 277 | static const int kPayloadUnit; |
| 278 | |
| 279 | private: |
[email protected] | ce208f87 | 2012-03-07 20:42:56 | [diff] [blame] | 280 | friend class PickleIterator; |
| 281 | |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 282 | Header* header_; |
| 283 | size_t header_size_; // Supports extra data between header and payload. |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 284 | // Allocation size of payload (or -1 if allocation is const). Note: this |
| 285 | // doesn't count the header. |
| 286 | size_t capacity_after_header_; |
| 287 | // The offset at which we will write the next field. Note: this doesn't count |
| 288 | // the header. |
| 289 | size_t write_offset_; |
| 290 | |
| 291 | // Just like WriteBytes, but with a compile-time size, for performance. |
[email protected] | ba72160 | 2014-06-11 00:34:38 | [diff] [blame] | 292 | template<size_t length> void BASE_EXPORT WriteBytesStatic(const void* data); |
[email protected] | d1b319fc | 2013-10-31 04:03:02 | [diff] [blame] | 293 | |
| 294 | // Writes a POD by copying its bytes. |
| 295 | template <typename T> bool WritePOD(const T& data) { |
| 296 | WriteBytesStatic<sizeof(data)>(&data); |
| 297 | return true; |
| 298 | } |
| 299 | inline void WriteBytesCommon(const void* data, size_t length); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 300 | |
[email protected] | a918f87 | 2010-06-01 14:30:51 | [diff] [blame] | 301 | FRIEND_TEST_ALL_PREFIXES(PickleTest, Resize); |
| 302 | FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); |
[email protected] | 137d237 | 2011-01-26 13:02:27 | [diff] [blame] | 303 | FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); |
[email protected] | 33a38dd | 2013-11-01 09:06:26 | [diff] [blame] | 304 | FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); |
initial.commit | d7cae12 | 2008-07-26 21:49:38 | [diff] [blame] | 305 | }; |
| 306 | |
tfarina | a3116351 | 2015-05-13 22:10:15 | [diff] [blame^] | 307 | #endif // BASE_PICKLE_H_ |