From 920d5c33d4d521e075d0418496379ff9d12f9cec Mon Sep 17 00:00:00 2001 From: Tony Liao Date: Tue, 3 Sep 2024 15:12:34 -0700 Subject: [PATCH] Remove the AnyMetadata class and use free functions instead. The way AnyMetadata works is by holding two pointers to the fields of google.protobuf.Any, and its methods `PackFrom` and `UnpackTo` mutates these pointers directly. This works but is a bit overcomplicated. A whole new object is created to mutate members of Any directly, breaking isolation. Each Any object will also need to unnecessarily create room to hold an AnyMetadata object, which is at minimum the size of two pointers. By removing AnyMetadata and using free functions, the call site passes `const Value& foo()` and `Value* mutable_foo()` directly into `PackFrom` and `UnpackTo`. This is more idiomatic and will play well with hasbits. The only catch here is that in some templated implementations of `PackFrom` and `UnpackTo`, caller will need access to T::FullMessageName(), which is in private scope. The workaround here is to have a single templated helper function that is made into a friend of google.protobuf.Any, so that it has the right visibility. PiperOrigin-RevId: 670722407 --- src/google/protobuf/any.cc | 26 ++- src/google/protobuf/any.h | 143 ++++++------- src/google/protobuf/any_lite.cc | 36 ++-- src/google/protobuf/any_test.cc | 5 - src/google/protobuf/compiler/cpp/file.cc | 3 +- src/google/protobuf/compiler/cpp/message.cc | 191 +++++++++--------- .../protobuf/compiler/java/java_features.pb.h | 7 +- src/google/protobuf/compiler/plugin.pb.h | 19 +- src/google/protobuf/cpp_features.pb.h | 7 +- src/google/protobuf/descriptor.pb.h | 135 +++++++++---- 10 files changed, 333 insertions(+), 239 deletions(-) diff --git a/src/google/protobuf/any.cc b/src/google/protobuf/any.cc index a10b68969c3c..106750877758 100644 --- a/src/google/protobuf/any.cc +++ b/src/google/protobuf/any.cc @@ -7,6 +7,7 @@ #include "google/protobuf/any.h" +#include "absl/strings/cord.h" #include "absl/strings/string_view.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/generated_message_util.h" @@ -19,21 +20,24 @@ namespace google { namespace protobuf { namespace internal { -bool AnyMetadata::PackFrom(Arena* arena, const Message& message) { - return PackFrom(arena, message, kTypeGoogleApisComPrefix); +using UrlType = std::string; +using ValueType = std::string; + +bool InternalPackFrom(const Message& message, UrlType* dst_url, + ValueType* dst_value) { + return InternalPackFromLite(message, kTypeGoogleApisComPrefix, + message.GetTypeName(), dst_url, dst_value); } -bool AnyMetadata::PackFrom(Arena* arena, const Message& message, - absl::string_view type_url_prefix) { - type_url_->Set(GetTypeUrl(message.GetTypeName(), type_url_prefix), arena); - return message.SerializeToString(value_->Mutable(arena)); +bool InternalPackFrom(const Message& message, absl::string_view type_url_prefix, + UrlType* dst_url, ValueType* dst_value) { + return InternalPackFromLite(message, type_url_prefix, message.GetTypeName(), + dst_url, dst_value); } -bool AnyMetadata::UnpackTo(Message* message) const { - if (!InternalIs(message->GetTypeName())) { - return false; - } - return message->ParseFromString(value_->Get()); +bool InternalUnpackTo(absl::string_view type_url, const ValueType& value, + Message* message) { + return InternalUnpackToLite(message->GetTypeName(), type_url, value, message); } bool GetAnyFieldDescriptors(const Message& message, diff --git a/src/google/protobuf/any.h b/src/google/protobuf/any.h index 539ead077971..fe8a1775c77b 100644 --- a/src/google/protobuf/any.h +++ b/src/google/protobuf/any.h @@ -12,7 +12,7 @@ #include "absl/strings/string_view.h" #include "google/protobuf/port.h" -#include "google/protobuf/arenastring.h" +#include "absl/strings/cord.h" #include "google/protobuf/message_lite.h" // Must be included last. @@ -36,75 +36,80 @@ PROTOBUF_EXPORT extern const char kTypeGoogleProdComPrefix[]; std::string GetTypeUrl(absl::string_view message_name, absl::string_view type_url_prefix); +template +absl::string_view GetAnyMessageName() { + return T::FullMessageName(); +} + // Helper class used to implement google::protobuf::Any. -class PROTOBUF_EXPORT AnyMetadata { - typedef ArenaStringPtr UrlType; - typedef ArenaStringPtr ValueType; - public: - // AnyMetadata does not take ownership of "type_url" and "value". - constexpr AnyMetadata(UrlType* type_url, ValueType* value) - : type_url_(type_url), value_(value) {} - AnyMetadata(const AnyMetadata&) = delete; - AnyMetadata& operator=(const AnyMetadata&) = delete; - - // Packs a message using the default type URL prefix: "type.googleapis.com". - // The resulted type URL will be "type.googleapis.com/". - // Returns false if serializing the message failed. - template - bool PackFrom(Arena* arena, const T& message) { - return InternalPackFrom(arena, message, kTypeGoogleApisComPrefix, - T::FullMessageName()); - } - - bool PackFrom(Arena* arena, const Message& message); - - // Packs a message using the given type URL prefix. The type URL will be - // constructed by concatenating the message type's full name to the prefix - // with an optional "/" separator if the prefix doesn't already end with "/". - // For example, both PackFrom(message, "type.googleapis.com") and - // PackFrom(message, "type.googleapis.com/") yield the same result type - // URL: "type.googleapis.com/". - // Returns false if serializing the message failed. - template - bool PackFrom(Arena* arena, const T& message, - absl::string_view type_url_prefix) { - return InternalPackFrom(arena, message, type_url_prefix, - T::FullMessageName()); - } - - bool PackFrom(Arena* arena, const Message& message, - absl::string_view type_url_prefix); - - // Unpacks the payload into the given message. Returns false if the message's - // type doesn't match the type specified in the type URL (i.e., the full - // name after the last "/" of the type URL doesn't match the message's actual - // full name) or parsing the payload has failed. - template - bool UnpackTo(T* message) const { - return InternalUnpackTo(T::FullMessageName(), message); - } - - bool UnpackTo(Message* message) const; - - // Checks whether the type specified in the type URL matches the given type. - // A type is considered matching if its full name matches the full name after - // the last "/" in the type URL. - template - bool Is() const { - return InternalIs(T::FullMessageName()); - } - - private: - bool InternalPackFrom(Arena* arena, const MessageLite& message, - absl::string_view type_url_prefix, - absl::string_view type_name); - bool InternalUnpackTo(absl::string_view type_name, - MessageLite* message) const; - bool InternalIs(absl::string_view type_name) const; - - UrlType* type_url_; - ValueType* value_; -}; +#define URL_TYPE std::string +#define VALUE_TYPE std::string + +// Helper functions that only require 'lite' messages to work. +PROTOBUF_EXPORT bool InternalPackFromLite(const MessageLite& message, + absl::string_view type_url_prefix, + absl::string_view type_name, + URL_TYPE* dst_url, + VALUE_TYPE* dst_value); +PROTOBUF_EXPORT bool InternalUnpackToLite(absl::string_view type_name, + absl::string_view type_url, + const VALUE_TYPE& value, + MessageLite* dst_message); +PROTOBUF_EXPORT bool InternalIsLite(absl::string_view type_name, + absl::string_view type_url); + +// Packs a message using the default type URL prefix: "type.googleapis.com". +// The resulted type URL will be "type.googleapis.com/". +// Returns false if serializing the message failed. +template +bool InternalPackFrom(const T& message, URL_TYPE* dst_url, + VALUE_TYPE* dst_value) { + return InternalPackFromLite(message, kTypeGoogleApisComPrefix, + GetAnyMessageName(), dst_url, dst_value); +} +PROTOBUF_EXPORT bool InternalPackFrom(const Message& message, URL_TYPE* dst_url, + VALUE_TYPE* dst_value); + +// Packs a message using the given type URL prefix. The type URL will be +// constructed by concatenating the message type's full name to the prefix +// with an optional "/" separator if the prefix doesn't already end with "/". +// For example, both InternalPackFrom(message, "type.googleapis.com") and +// InternalPackFrom(message, "type.googleapis.com/") yield the same result type +// URL: "type.googleapis.com/". +// Returns false if serializing the message failed. +template +bool InternalPackFrom(const T& message, absl::string_view type_url_prefix, + URL_TYPE* dst_url, VALUE_TYPE* dst_value) { + return InternalPackFromLite(message, type_url_prefix, GetAnyMessageName(), + dst_url, dst_value); +} +PROTOBUF_EXPORT bool InternalPackFrom(const Message& message, + absl::string_view type_url_prefix, + URL_TYPE* dst_url, VALUE_TYPE* dst_value); + +// Unpacks the payload into the given message. Returns false if the message's +// type doesn't match the type specified in the type URL (i.e., the full +// name after the last "/" of the type URL doesn't match the message's actual +// full name) or parsing the payload has failed. +template +bool InternalUnpackTo(absl::string_view type_url, const VALUE_TYPE& value, + T* message) { + return InternalUnpackToLite(GetAnyMessageName(), type_url, value, message); +} +PROTOBUF_EXPORT bool InternalUnpackTo(absl::string_view type_url, + const VALUE_TYPE& value, + Message* message); + +// Checks whether the type specified in the type URL matches the given type. +// A type is considered matching if its full name matches the full name after +// the last "/" in the type URL. +template +bool InternalIs(absl::string_view type_url) { + return InternalIsLite(GetAnyMessageName(), type_url); +} + +#undef URL_TYPE +#undef VALUE_TYPE // Get the proto type name from Any::type_url value. For example, passing // "type.googleapis.com/rpc.QueryOrigin" will return "rpc.QueryOrigin" in diff --git a/src/google/protobuf/any_lite.cc b/src/google/protobuf/any_lite.cc index 5c3638e1f6ff..7f68294fd956 100644 --- a/src/google/protobuf/any_lite.cc +++ b/src/google/protobuf/any_lite.cc @@ -8,6 +8,7 @@ #include #include +#include "absl/strings/cord.h" #include "absl/strings/match.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" @@ -20,6 +21,13 @@ namespace google { namespace protobuf { namespace internal { +using UrlType = std::string; +using ValueType = std::string; + +const char kAnyFullTypeName[] = "google.protobuf.Any"; +const char kTypeGoogleApisComPrefix[] = "type.googleapis.com/"; +const char kTypeGoogleProdComPrefix[] = "type.googleprod.com/"; + std::string GetTypeUrl(absl::string_view message_name, absl::string_view type_url_prefix) { if (!type_url_prefix.empty() && @@ -36,27 +44,25 @@ bool EndsWithTypeName(absl::string_view type_url, absl::string_view type_name) { absl::EndsWith(type_url, type_name); } -const char kAnyFullTypeName[] = "google.protobuf.Any"; -const char kTypeGoogleApisComPrefix[] = "type.googleapis.com/"; -const char kTypeGoogleProdComPrefix[] = "type.googleprod.com/"; - -bool AnyMetadata::InternalPackFrom(Arena* arena, const MessageLite& message, - absl::string_view type_url_prefix, - absl::string_view type_name) { - type_url_->Set(GetTypeUrl(type_name, type_url_prefix), arena); - return message.SerializeToString(value_->Mutable(arena)); +bool InternalPackFromLite(const MessageLite& message, + absl::string_view type_url_prefix, + absl::string_view type_name, UrlType* dst_url, + ValueType* dst_value) { + *dst_url = GetTypeUrl(type_name, type_url_prefix); + return message.SerializeToString(dst_value); } -bool AnyMetadata::InternalUnpackTo(absl::string_view type_name, - MessageLite* message) const { - if (!InternalIs(type_name)) { +bool InternalUnpackToLite(absl::string_view type_name, + absl::string_view type_url, const ValueType& value, + MessageLite* dst_message) { + if (!InternalIsLite(type_name, type_url)) { return false; } - return message->ParseFromString(value_->Get()); + return dst_message->ParseFromString(value); } -bool AnyMetadata::InternalIs(absl::string_view type_name) const { - return EndsWithTypeName(type_url_->Get(), type_name); +bool InternalIsLite(absl::string_view type_name, absl::string_view type_url) { + return EndsWithTypeName(type_url, type_name); } bool ParseAnyTypeUrl(absl::string_view type_url, std::string* url_prefix, diff --git a/src/google/protobuf/any_test.cc b/src/google/protobuf/any_test.cc index 3b041716788d..400e90c9933a 100644 --- a/src/google/protobuf/any_test.cc +++ b/src/google/protobuf/any_test.cc @@ -24,11 +24,6 @@ namespace google { namespace protobuf { namespace { -TEST(AnyMetadataTest, ConstInit) { - PROTOBUF_CONSTINIT static internal::AnyMetadata metadata(nullptr, nullptr); - (void)metadata; -} - TEST(AnyTest, TestPackAndUnpack) { protobuf_unittest::TestAny submessage; submessage.set_int32_value(12345); diff --git a/src/google/protobuf/compiler/cpp/file.cc b/src/google/protobuf/compiler/cpp/file.cc index 9ad4783d4db4..7637a9c73d2a 100644 --- a/src/google/protobuf/compiler/cpp/file.cc +++ b/src/google/protobuf/compiler/cpp/file.cc @@ -236,7 +236,8 @@ void FileGenerator::GenerateSharedHeaderCode(io::Printer* p) { NamespaceOpener ns(ProtobufNamespace(options_), p); p->Emit(R"cc( namespace internal { - class AnyMetadata; + template + ::absl::string_view GetAnyMessageName(); } // namespace internal )cc"); }}, diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index 23755a13b9e1..0901ac55b9cc 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -1551,15 +1551,6 @@ void MessageGenerator::GenerateImplDefinition(io::Printer* p) { ::$proto_ns$::internal::WeakFieldMap _weak_field_map_; )cc"); }}, - {"any_metadata", - [&] { - // Generate _any_metadata_ for the Any type. - if (!IsAnyMessage(descriptor_)) return; - - p->Emit(R"cc( - ::$proto_ns$::internal::AnyMetadata _any_metadata_; - )cc"); - }}, {"union_impl", [&] { // Only create the _impl_ field if it contains data. @@ -1593,7 +1584,6 @@ void MessageGenerator::GenerateImplDefinition(io::Printer* p) { $cached_size_if_no_hasbits$; $oneof_case$; $weak_field_map$; - $any_metadata$; //~ For detecting when concurrent accessor calls cause races. PROTOBUF_TSAN_DECLARE_MEMBER }; @@ -1606,82 +1596,95 @@ void MessageGenerator::GenerateImplDefinition(io::Printer* p) { void MessageGenerator::GenerateAnyMethodDefinition(io::Printer* p) { ABSL_DCHECK(IsAnyMessage(descriptor_)); - p->Emit({{"any_methods", - [&] { - if (HasDescriptorMethods(descriptor_->file(), options_)) { - p->Emit( - R"cc( - bool PackFrom(const ::$proto_ns$::Message& message) { - $DCHK$_NE(&message, this); - return $any_metadata$.PackFrom(GetArena(), message); - } - bool PackFrom(const ::$proto_ns$::Message& message, - ::absl::string_view type_url_prefix) { - $DCHK$_NE(&message, this); - return $any_metadata$.PackFrom(GetArena(), message, type_url_prefix); - } - bool UnpackTo(::$proto_ns$::Message* message) const { - return $any_metadata$.UnpackTo(message); - } - static bool GetAnyFieldDescriptors( - const ::$proto_ns$::Message& message, - const ::$proto_ns$::FieldDescriptor** type_url_field, - const ::$proto_ns$::FieldDescriptor** value_field); - template < - typename T, - class = typename std::enable_if::value>::type> - bool PackFrom(const T& message) { - return $any_metadata$.PackFrom(GetArena(), message); - } - template < - typename T, - class = typename std::enable_if::value>::type> - bool PackFrom(const T& message, - ::absl::string_view type_url_prefix) { - return $any_metadata$.PackFrom(GetArena(), message, type_url_prefix); - } - template < - typename T, - class = typename std::enable_if::value>::type> - bool UnpackTo(T* message) const { - return $any_metadata$.UnpackTo(message); - } - )cc"); - } else { - p->Emit( - R"cc( - template - bool PackFrom(const T& message) { - return $any_metadata$.PackFrom(GetArena(), message); - } - template - bool PackFrom(const T& message, - ::absl::string_view type_url_prefix) { - return $any_metadata$.PackFrom(GetArena(), message, type_url_prefix); - } - template - bool UnpackTo(T* message) const { - return $any_metadata$.UnpackTo(message); - } - )cc"); - } - }}}, - R"cc( - // implements Any - // ----------------------------------------------- + p->Emit( + {{"any_methods", + [&] { + if (HasDescriptorMethods(descriptor_->file(), options_)) { + p->Emit( + R"cc( + bool PackFrom(const ::$proto_ns$::Message& message) { + $DCHK$_NE(&message, this); + return ::$proto_ns$::internal::InternalPackFrom( + message, mutable_type_url(), _internal_mutable_value()); + } + bool PackFrom(const ::$proto_ns$::Message& message, + ::absl::string_view type_url_prefix) { + $DCHK$_NE(&message, this); + return ::$proto_ns$::internal::InternalPackFrom( + message, type_url_prefix, mutable_type_url(), + _internal_mutable_value()); + } + bool UnpackTo(::$proto_ns$::Message* message) const { + return ::$proto_ns$::internal::InternalUnpackTo( + _internal_type_url(), _internal_value(), message); + } + static bool GetAnyFieldDescriptors( + const ::$proto_ns$::Message& message, + const ::$proto_ns$::FieldDescriptor** type_url_field, + const ::$proto_ns$::FieldDescriptor** value_field); + template < + typename T, + class = typename std::enable_if::value>::type> + bool PackFrom(const T& message) { + return ::$proto_ns$::internal::InternalPackFrom( + message, mutable_type_url(), _internal_mutable_value()); + } + template < + typename T, + class = typename std::enable_if::value>::type> + bool PackFrom(const T& message, + ::absl::string_view type_url_prefix) { + return ::$proto_ns$::internal::InternalPackFrom( + message, type_url_prefix, mutable_type_url(), + _internal_mutable_value()); + } + template < + typename T, + class = typename std::enable_if::value>::type> + bool UnpackTo(T* message) const { + return ::$proto_ns$::internal::InternalUnpackTo( + _internal_type_url(), _internal_value(), message); + } + )cc"); + } else { + p->Emit( + R"cc( + template + bool PackFrom(const T& message) { + return ::$proto_ns$::internal::InternalPackFrom( + message, mutable_type_url(), _internal_mutable_value()); + } + template + bool PackFrom(const T& message, + ::absl::string_view type_url_prefix) { + return ::$proto_ns$::internal::InternalPackFrom( + message, type_url_prefix, mutable_type_url(), + _internal_mutable_value()); + } + template + bool UnpackTo(T* message) const { + return ::$proto_ns$::internal::InternalUnpackTo( + _internal_type_url(), _internal_value(), message); + } + )cc"); + } + }}}, + R"cc( + // implements Any + // ----------------------------------------------- - $any_methods$; + $any_methods$; - template - bool Is() const { - return $any_metadata$.Is(); - } - static bool ParseAnyTypeUrl(::absl::string_view type_url, - std::string* full_type_name); - )cc"); + template + bool Is() const { + return ::$proto_ns$::internal::InternalIs(_internal_type_url()); + } + static bool ParseAnyTypeUrl(::absl::string_view type_url, + std::string* full_type_name); + )cc"); } void MessageGenerator::GenerateClassDefinition(io::Printer* p) { @@ -2147,10 +2150,16 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { $generated_methods$; $internal_field_number$; $decl_non_simple_base$; - //~ Friend AnyMetadata so that it can call this FullMessageName() - //~ method. + //~ Friend the template function GetAnyMessageName() so that it can + //~ call this FullMessageName() method. + //~ NOTE: parentheses around the symbol GetAnyMessageName is required + //~ for compiler to resolve the symbol correctly and interpret + //~ it as a function (instead of trying to find the symbol under + //~ the absl::string_view namespace). private: - friend class ::$proto_ns$::internal::AnyMetadata; + template + friend ::absl::string_view( + ::$proto_ns$::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "$full_name$"; } $decl_annotate$; @@ -2797,13 +2806,6 @@ void MessageGenerator::GenerateImplMemberInit(io::Printer* p, } }; - auto init_any_metadata = [&] { - if (IsAnyMessage(descriptor_)) { - separator(); - p->Emit("_any_metadata_{&type_url_, &value_}"); - } - }; - // Initialization order of the various fields inside `_impl_(...)` init_extensions(); init_inlined_string_indices(); @@ -2814,7 +2816,6 @@ void MessageGenerator::GenerateImplMemberInit(io::Printer* p, init_cached_size_if_no_hasbits(); init_oneof_cases(); init_weak_field_map(); - init_any_metadata(); } void MessageGenerator::GenerateSharedConstructorCode(io::Printer* p) { diff --git a/src/google/protobuf/compiler/java/java_features.pb.h b/src/google/protobuf/compiler/java/java_features.pb.h index 5ff2b9de6726..9c21c13fc883 100644 --- a/src/google/protobuf/compiler/java/java_features.pb.h +++ b/src/google/protobuf/compiler/java/java_features.pb.h @@ -40,7 +40,8 @@ namespace google { namespace protobuf { namespace internal { -class AnyMetadata; +template +::absl::string_view GetAnyMessageName(); } // namespace internal } // namespace protobuf } // namespace google @@ -221,7 +222,9 @@ class PROTOC_EXPORT JavaFeatures final void SharedDtor(); void InternalSwap(JavaFeatures* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "pb.JavaFeatures"; } protected: diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 3fafe89543d8..c476ca4e9243 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -46,7 +46,8 @@ namespace google { namespace protobuf { namespace internal { -class AnyMetadata; +template +::absl::string_view GetAnyMessageName(); } // namespace internal } // namespace protobuf } // namespace google @@ -238,7 +239,9 @@ class PROTOC_EXPORT Version final void SharedDtor(); void InternalSwap(Version* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.compiler.Version"; } protected: @@ -475,7 +478,9 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final void SharedDtor(); void InternalSwap(CodeGeneratorResponse_File* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.compiler.CodeGeneratorResponse.File"; } protected: @@ -728,7 +733,9 @@ class PROTOC_EXPORT CodeGeneratorResponse final void SharedDtor(); void InternalSwap(CodeGeneratorResponse* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.compiler.CodeGeneratorResponse"; } protected: @@ -1010,7 +1017,9 @@ class PROTOC_EXPORT CodeGeneratorRequest final void SharedDtor(); void InternalSwap(CodeGeneratorRequest* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.compiler.CodeGeneratorRequest"; } protected: diff --git a/src/google/protobuf/cpp_features.pb.h b/src/google/protobuf/cpp_features.pb.h index 97d4744bce40..6f96cc61cd6a 100644 --- a/src/google/protobuf/cpp_features.pb.h +++ b/src/google/protobuf/cpp_features.pb.h @@ -40,7 +40,8 @@ namespace google { namespace protobuf { namespace internal { -class AnyMetadata; +template +::absl::string_view GetAnyMessageName(); } // namespace internal } // namespace protobuf } // namespace google @@ -222,7 +223,9 @@ class PROTOBUF_EXPORT CppFeatures final void SharedDtor(); void InternalSwap(CppFeatures* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "pb.CppFeatures"; } protected: diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index fb1df692acea..5605921c35a4 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -39,7 +39,8 @@ namespace google { namespace protobuf { namespace internal { -class AnyMetadata; +template +::absl::string_view GetAnyMessageName(); } // namespace internal } // namespace protobuf } // namespace google @@ -829,7 +830,9 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart final void SharedDtor(); void InternalSwap(UninterpretedOption_NamePart* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.UninterpretedOption.NamePart"; } protected: @@ -1040,7 +1043,9 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final void SharedDtor(); void InternalSwap(SourceCodeInfo_Location* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.SourceCodeInfo.Location"; } protected: @@ -1323,7 +1328,9 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final void SharedDtor(); void InternalSwap(GeneratedCodeInfo_Annotation* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.GeneratedCodeInfo.Annotation"; } protected: @@ -1601,7 +1608,9 @@ class PROTOBUF_EXPORT FieldOptions_FeatureSupport final void SharedDtor(); void InternalSwap(FieldOptions_FeatureSupport* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.FieldOptions.FeatureSupport"; } protected: @@ -1838,7 +1847,9 @@ class PROTOBUF_EXPORT FieldOptions_EditionDefault final void SharedDtor(); void InternalSwap(FieldOptions_EditionDefault* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.FieldOptions.EditionDefault"; } protected: @@ -2054,7 +2065,9 @@ class PROTOBUF_EXPORT FeatureSet final void SharedDtor(); void InternalSwap(FeatureSet* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.FeatureSet"; } protected: @@ -2612,7 +2625,9 @@ class PROTOBUF_EXPORT ExtensionRangeOptions_Declaration final void SharedDtor(); void InternalSwap(ExtensionRangeOptions_Declaration* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.ExtensionRangeOptions.Declaration"; } protected: @@ -2868,7 +2883,9 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange final void SharedDtor(); void InternalSwap(EnumDescriptorProto_EnumReservedRange* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.EnumDescriptorProto.EnumReservedRange"; } protected: @@ -3073,7 +3090,9 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange final void SharedDtor(); void InternalSwap(DescriptorProto_ReservedRange* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.DescriptorProto.ReservedRange"; } protected: @@ -3283,7 +3302,9 @@ class PROTOBUF_EXPORT UninterpretedOption final void SharedDtor(); void InternalSwap(UninterpretedOption* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.UninterpretedOption"; } protected: @@ -3578,7 +3599,9 @@ class PROTOBUF_EXPORT SourceCodeInfo final void SharedDtor(); void InternalSwap(SourceCodeInfo* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.SourceCodeInfo"; } protected: @@ -3776,7 +3799,9 @@ class PROTOBUF_EXPORT GeneratedCodeInfo final void SharedDtor(); void InternalSwap(GeneratedCodeInfo* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.GeneratedCodeInfo"; } protected: @@ -3979,7 +4004,9 @@ class PROTOBUF_EXPORT FeatureSetDefaults_FeatureSetEditionDefault final void SharedDtor(); void InternalSwap(FeatureSetDefaults_FeatureSetEditionDefault* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.FeatureSetDefaults.FeatureSetEditionDefault"; } protected: @@ -4210,7 +4237,9 @@ class PROTOBUF_EXPORT ServiceOptions final void SharedDtor(); void InternalSwap(ServiceOptions* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.ServiceOptions"; } protected: @@ -4623,7 +4652,9 @@ class PROTOBUF_EXPORT OneofOptions final void SharedDtor(); void InternalSwap(OneofOptions* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.OneofOptions"; } protected: @@ -5023,7 +5054,9 @@ class PROTOBUF_EXPORT MethodOptions final void SharedDtor(); void InternalSwap(MethodOptions* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.MethodOptions"; } protected: @@ -5469,7 +5502,9 @@ class PROTOBUF_EXPORT MessageOptions final void SharedDtor(); void InternalSwap(MessageOptions* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.MessageOptions"; } protected: @@ -5934,7 +5969,9 @@ class PROTOBUF_EXPORT FileOptions final void SharedDtor(); void InternalSwap(FileOptions* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.FileOptions"; } protected: @@ -6661,7 +6698,9 @@ class PROTOBUF_EXPORT FieldOptions final void SharedDtor(); void InternalSwap(FieldOptions* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.FieldOptions"; } protected: @@ -7324,7 +7363,9 @@ class PROTOBUF_EXPORT FeatureSetDefaults final void SharedDtor(); void InternalSwap(FeatureSetDefaults* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.FeatureSetDefaults"; } protected: @@ -7554,7 +7595,9 @@ class PROTOBUF_EXPORT ExtensionRangeOptions final void SharedDtor(); void InternalSwap(ExtensionRangeOptions* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.ExtensionRangeOptions"; } protected: @@ -8006,7 +8049,9 @@ class PROTOBUF_EXPORT EnumValueOptions final void SharedDtor(); void InternalSwap(EnumValueOptions* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.EnumValueOptions"; } protected: @@ -8449,7 +8494,9 @@ class PROTOBUF_EXPORT EnumOptions final void SharedDtor(); void InternalSwap(EnumOptions* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.EnumOptions"; } protected: @@ -8888,7 +8935,9 @@ class PROTOBUF_EXPORT OneofDescriptorProto final void SharedDtor(); void InternalSwap(OneofDescriptorProto* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.OneofDescriptorProto"; } protected: @@ -9108,7 +9157,9 @@ class PROTOBUF_EXPORT MethodDescriptorProto final void SharedDtor(); void InternalSwap(MethodDescriptorProto* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.MethodDescriptorProto"; } protected: @@ -9392,7 +9443,9 @@ class PROTOBUF_EXPORT FieldDescriptorProto final void SharedDtor(); void InternalSwap(FieldDescriptorProto* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.FieldDescriptorProto"; } protected: @@ -9808,7 +9861,9 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto final void SharedDtor(); void InternalSwap(EnumValueDescriptorProto* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.EnumValueDescriptorProto"; } protected: @@ -10041,7 +10096,9 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final void SharedDtor(); void InternalSwap(DescriptorProto_ExtensionRange* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.DescriptorProto.ExtensionRange"; } protected: @@ -10268,7 +10325,9 @@ class PROTOBUF_EXPORT ServiceDescriptorProto final void SharedDtor(); void InternalSwap(ServiceDescriptorProto* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.ServiceDescriptorProto"; } protected: @@ -10507,7 +10566,9 @@ class PROTOBUF_EXPORT EnumDescriptorProto final void SharedDtor(); void InternalSwap(EnumDescriptorProto* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.EnumDescriptorProto"; } protected: @@ -10790,7 +10851,9 @@ class PROTOBUF_EXPORT DescriptorProto final void SharedDtor(); void InternalSwap(DescriptorProto* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.DescriptorProto"; } protected: @@ -11169,7 +11232,9 @@ class PROTOBUF_EXPORT FileDescriptorProto final void SharedDtor(); void InternalSwap(FileDescriptorProto* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.FileDescriptorProto"; } protected: @@ -11597,7 +11662,9 @@ class PROTOBUF_EXPORT FileDescriptorSet final void SharedDtor(); void InternalSwap(FileDescriptorSet* other); private: - friend class ::google::protobuf::internal::AnyMetadata; + template + friend ::absl::string_view( + ::google::protobuf::internal::GetAnyMessageName)(); static ::absl::string_view FullMessageName() { return "google.protobuf.FileDescriptorSet"; } protected: