diff options
Diffstat (limited to 'src/google/protobuf/message.h')
-rw-r--r-- | src/google/protobuf/message.h | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index cd25faa2..d96fcc60 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -95,7 +95,7 @@ // foo->ParseFromString(data); // // // Use the reflection interface to examine the contents. -// Reflection* reflection = foo->GetReflection(); +// const Reflection* reflection = foo->GetReflection(); // assert(reflection->GetString(foo, text_field) == "Hello World!"); // assert(reflection->CountField(foo, numbers_field) == 3); // assert(reflection->GetInt32(foo, numbers_field, 0) == 1); @@ -315,6 +315,16 @@ class LIBPROTOBUF_EXPORT Message { bool SerializePartialToOstream(ostream* output) const; + // Make a string encoding the message. Is equivalent to calling + // SerializeToString() on a string and using that. Returns the empty + // string if SerializeToString() would have returned an error. + // Note: If you intend to generate many such strings, you may + // reduce heap fragmentation by instead re-using the same string + // object with calls to SerializeToString(). + string SerializeAsString() const; + // Like SerializeAsString(), but allows missing required fields. + string SerializePartialAsString() const; + // Like SerializeToString(), but appends to the data to the string's existing // contents. All required fields must be set. bool AppendToString(string* output) const; @@ -326,6 +336,11 @@ class LIBPROTOBUF_EXPORT Message { // this, it MUST override SetCachedSize(). virtual int ByteSize() const; + // Computes (an estimate of) the total number of bytes currently used for + // storing the message in memory. The default implementation calls the + // Reflection object's SpaceUsed() method. + virtual int SpaceUsed() const; + // Serializes the message without recomputing the size. The message must // not have changed since the last call to ByteSize(); if it has, the results // are undefined. @@ -432,6 +447,9 @@ class LIBPROTOBUF_EXPORT Reflection { // recognized according to the Message's definition. virtual UnknownFieldSet* MutableUnknownFields(Message* message) const = 0; + // Estimate the amount of memory used by the message object. + virtual int SpaceUsed(const Message& message) const = 0; + // Check if the given non-repeated field is set. virtual bool HasField(const Message& message, const FieldDescriptor* field) const = 0; |