aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/message_lite.h
diff options
context:
space:
mode:
authorGravatar Adam Cozzette <acozzette@google.com>2016-11-17 16:48:38 -0800
committerGravatar Adam Cozzette <acozzette@google.com>2016-11-17 16:59:59 -0800
commit5a76e633ea9b5adb215e93fdc11e1c0c08b3fc74 (patch)
tree0276f81f8848a05d84cd7e287b43d665e30f04e3 /src/google/protobuf/message_lite.h
parente28286fa05d8327fd6c5aa70cfb3be558f0932b8 (diff)
Integrated internal changes from Google
Diffstat (limited to 'src/google/protobuf/message_lite.h')
-rw-r--r--src/google/protobuf/message_lite.h22
1 files changed, 14 insertions, 8 deletions
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 <google/protobuf/stubs/common.h>
+#include <google/protobuf/stubs/logging.h>
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<size_t>(INT_MAX));
+ return static_cast<int>(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;