From 3508374f771d21aa27b7cc6fe5ccdc475d23c26c Mon Sep 17 00:00:00 2001 From: chenBright Date: Mon, 11 May 2026 17:19:26 +0800 Subject: [PATCH] Fix protobuf version compatibility for ByteSizeLong() and SpaceUsedLong() --- src/brpc/memcache.cpp | 1 + src/brpc/nonreflectable_message.h | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/src/brpc/memcache.cpp b/src/brpc/memcache.cpp index 489d84db16..c7d6f836b1 100644 --- a/src/brpc/memcache.cpp +++ b/src/brpc/memcache.cpp @@ -17,6 +17,7 @@ #include "brpc/memcache.h" +#include #include "brpc/policy/memcache_binary_header.h" #include "brpc/proto_base.pb.h" #include "butil/logging.h" diff --git a/src/brpc/nonreflectable_message.h b/src/brpc/nonreflectable_message.h index 7f2acd78a3..f805389e42 100644 --- a/src/brpc/nonreflectable_message.h +++ b/src/brpc/nonreflectable_message.h @@ -163,9 +163,19 @@ class NonreflectableMessage : public ::google::protobuf::Message { #endif // Size of bytes after serialization. +#if GOOGLE_PROTOBUF_VERSION < 3004000 + virtual size_t ByteSizeLong() const { + return 0; + } + + int ByteSize() const override { + return static_cast(ByteSizeLong()); + } +#else size_t ByteSizeLong() const override { return 0; } +#endif #if GOOGLE_PROTOBUF_VERSION >= 3007000 && GOOGLE_PROTOBUF_VERSION < 3010000 void SerializeWithCachedSizes(::google::protobuf::io::CodedOutputStream*) const override {}