Chromium Code Reviews| Index: base/pickle.h |
| diff --git a/base/pickle.h b/base/pickle.h |
| index e50fd68eb8e4b82a2a14dc89e285a52ff207f894..41089539c593e0bd0e1f4e56656f9bf36c59656c 100644 |
| --- a/base/pickle.h |
| +++ b/base/pickle.h |
| @@ -109,6 +109,43 @@ class BASE_EXPORT PickleIterator { |
| FRIEND_TEST_ALL_PREFIXES(PickleTest, GetReadPointerAndAdvance); |
| }; |
| +// This class provides an interface analogous to base::Pickle's WriteFoo() |
| +// methods and can be used to accurately compute the size of a hypothetical |
| +// Pickle's payload without thinking too hard about the actual size of each |
|
jam
2016/02/03 22:47:11
nit: thinking too hard->having to reference the Pi
Ken Rockot(use gerrit already)
2016/02/04 03:55:12
done
|
| +// write operation. |
| +class BASE_EXPORT PickleSizer { |
| + public: |
| + PickleSizer(); |
| + ~PickleSizer(); |
| + |
| + // Returns the computed size of the payload. |
| + size_t payload_size() const { return payload_size_; } |
| + |
| + void AddBool() { return AddInt(); } |
| + void AddInt() { AddPOD<int>(); } |
| + void AddLongUsingDangerousNonPortableLessPersistableForm() { AddPOD<long>(); } |
| + void AddUInt16() { return AddPOD<uint16_t>(); } |
| + void AddUInt32() { return AddPOD<uint32_t>(); } |
| + void AddInt64() { return AddPOD<int64_t>(); } |
| + void AddUInt64() { return AddPOD<uint64_t>(); } |
| + void AddSizeT() { return AddPOD<uint64_t>(); } |
| + void AddFloat() { return AddPOD<float>(); } |
| + void AddDouble() { return AddPOD<double>(); } |
| + void AddString(const StringPiece& value); |
| + void AddString16(const StringPiece16& value); |
| + void AddData(int length); |
| + void AddBytes(int length); |
| + |
| + private: |
| + // Just like AddBytes() but with a compile-time size for performance. |
| + template<size_t length> void BASE_EXPORT AddBytesStatic(); |
| + |
| + template <typename T> |
| + void AddPOD() { AddBytesStatic<sizeof(T)>(); } |
| + |
| + size_t payload_size_ = 0; |
| +}; |
| + |
| // This class provides facilities for basic binary value packing and unpacking. |
| // |
| // The Pickle class supports appending primitive values (ints, strings, etc.) |