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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/files/file_path.cc ('k') | base/pickle.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/pickle.h
diff --git a/base/pickle.h b/base/pickle.h
index e50fd68eb8e4b82a2a14dc89e285a52ff207f894..18d8afe21d4a6c289a37f79d738567f7b5103467 100644
--- a/base/pickle.h
+++ b/base/pickle.h
@@ -109,6 +109,42 @@ 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 having to reference the Pickle implementation.
+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.)
« 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