From 5a76e633ea9b5adb215e93fdc11e1c0c08b3fc74 Mon Sep 17 00:00:00 2001 From: Adam Cozzette Date: Thu, 17 Nov 2016 16:48:38 -0800 Subject: Integrated internal changes from Google --- src/google/protobuf/message_lite.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/google/protobuf/message_lite.h') diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index d3c3b1f0..d5de8cdb 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -40,6 +40,7 @@ #define GOOGLE_PROTOBUF_MESSAGE_LITE_H__ #include +#include namespace google { @@ -239,17 +240,22 @@ class LIBPROTOBUF_EXPORT MessageLite { bool AppendPartialToString(string* output) const; // Computes the serialized size of the message. This recursively calls - // ByteSize() on all embedded messages. Subclasses MUST override either - // ByteSize() or ByteSizeLong() (overriding both is fine). + // ByteSizeLong() on all embedded messages. // - // ByteSize() is generally linear in the number of fields defined for the + // ByteSizeLong() is generally linear in the number of fields defined for the // proto. - virtual int ByteSize() const { return ByteSizeLong(); } - virtual size_t ByteSizeLong() const; + virtual size_t ByteSizeLong() const = 0; - // 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. + // Legacy ByteSize() API. + int ByteSize() const { + size_t result = ByteSizeLong(); + GOOGLE_DCHECK_LE(result, static_cast(INT_MAX)); + return static_cast(result); + } + + // Serializes the message without recomputing the size. The message must not + // have changed since the last call to ByteSize(), and the value returned by + // ByteSize must be non-negative. Otherwise the results are undefined. virtual void SerializeWithCachedSizes( io::CodedOutputStream* output) const = 0; -- cgit v1.2.3