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

Side by Side Diff: base/pickle.h

Issue 1655333002: Add message sizing to basic IPC traits and struct macros. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@with-pickles
Patch Set: include ArrayHeader in size (oops!) and ensure the buffer doesn't relocate Created 4 years, 10 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
« no previous file with comments | « base/files/file_path.cc ('k') | base/pickle.cc » ('j') | no next file with comments »
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 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 const char* GetReadPointerAndAdvance(int num_elements, 102 const char* GetReadPointerAndAdvance(int num_elements,
103 size_t size_element); 103 size_t size_element);
104 104
105 const char* payload_; // Start of our pickle's payload. 105 const char* payload_; // Start of our pickle's payload.
106 size_t read_index_; // Offset of the next readable byte in payload. 106 size_t read_index_; // Offset of the next readable byte in payload.
107 size_t end_index_; // Payload size. 107 size_t end_index_; // Payload size.
108 108
109 FRIEND_TEST_ALL_PREFIXES(PickleTest, GetReadPointerAndAdvance); 109 FRIEND_TEST_ALL_PREFIXES(PickleTest, GetReadPointerAndAdvance);
110 }; 110 };
111 111
112 // This class provides an interface analogous to base::Pickle's WriteFoo()
113 // methods and can be used to accurately compute the size of a hypothetical
114 // Pickle's payload without having to reference the Pickle implementation.
115 class BASE_EXPORT PickleSizer {
116 public:
117 PickleSizer();
118 ~PickleSizer();
119
120 // Returns the computed size of the payload.
121 size_t payload_size() const { return payload_size_; }
122
123 void AddBool() { return AddInt(); }
124 void AddInt() { AddPOD<int>(); }
125 void AddLongUsingDangerousNonPortableLessPersistableForm() { AddPOD<long>(); }
126 void AddUInt16() { return AddPOD<uint16_t>(); }
127 void AddUInt32() { return AddPOD<uint32_t>(); }
128 void AddInt64() { return AddPOD<int64_t>(); }
129 void AddUInt64() { return AddPOD<uint64_t>(); }
130 void AddSizeT() { return AddPOD<uint64_t>(); }
131 void AddFloat() { return AddPOD<float>(); }
132 void AddDouble() { return AddPOD<double>(); }
133 void AddString(const StringPiece& value);
134 void AddString16(const StringPiece16& value);
135 void AddData(int length);
136 void AddBytes(int length);
137
138 private:
139 // Just like AddBytes() but with a compile-time size for performance.
140 template<size_t length> void BASE_EXPORT AddBytesStatic();
141
142 template <typename T>
143 void AddPOD() { AddBytesStatic<sizeof(T)>(); }
144
145 size_t payload_size_ = 0;
146 };
147
112 // This class provides facilities for basic binary value packing and unpacking. 148 // This class provides facilities for basic binary value packing and unpacking.
113 // 149 //
114 // The Pickle class supports appending primitive values (ints, strings, etc.) 150 // The Pickle class supports appending primitive values (ints, strings, etc.)
115 // to a pickle instance. The Pickle instance grows its internal memory buffer 151 // to a pickle instance. The Pickle instance grows its internal memory buffer
116 // dynamically to hold the sequence of primitive values. The internal memory 152 // dynamically to hold the sequence of primitive values. The internal memory
117 // buffer is exposed as the "data" of the Pickle. This "data" can be passed 153 // buffer is exposed as the "data" of the Pickle. This "data" can be passed
118 // to a Pickle object to initialize it for reading. 154 // to a Pickle object to initialize it for reading.
119 // 155 //
120 // When reading from a Pickle object, it is important for the consumer to know 156 // When reading from a Pickle object, it is important for the consumer to know
121 // what value types to read and in what order to read them as the Pickle does 157 // what value types to read and in what order to read them as the Pickle does
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext); 385 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNext);
350 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow); 386 FRIEND_TEST_ALL_PREFIXES(PickleTest, PeekNextOverflow);
351 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext); 387 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNext);
352 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader); 388 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextWithIncompleteHeader);
353 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow); 389 FRIEND_TEST_ALL_PREFIXES(PickleTest, FindNextOverflow);
354 }; 390 };
355 391
356 } // namespace base 392 } // namespace base
357 393
358 #endif // BASE_PICKLE_H_ 394 #endif // BASE_PICKLE_H_
OLDNEW
« no previous file with comments | « base/files/file_path.cc ('k') | base/pickle.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698