From 73fe084436f99bf4b8e2c309e72c93802cf91605 Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Wed, 2 Oct 2024 13:40:53 -0700 Subject: [PATCH] Move out hpb::HasExtension and hpb::ClearExtension to extension.h PiperOrigin-RevId: 681576188 --- hpb/extension.h | 41 +++++++++++++++++++++++++++++++++++++++++ hpb/hpb.h | 35 ----------------------------------- 2 files changed, 41 insertions(+), 35 deletions(-) diff --git a/hpb/extension.h b/hpb/extension.h index eb9e79f14d..aeb3b8de98 100644 --- a/hpb/extension.h +++ b/hpb/extension.h @@ -11,6 +11,11 @@ #include #include +#include "absl/base/attributes.h" +#include "google/protobuf/hpb/backend/upb/interop.h" +#include "google/protobuf/hpb/internal/message_lock.h" +#include "google/protobuf/hpb/internal/template_help.h" +#include "google/protobuf/hpb/ptr.h" #include "upb/mem/arena.hpp" #include "upb/mini_table/extension.h" #include "upb/mini_table/extension_registry.h" @@ -87,6 +92,42 @@ class ExtensionRegistry { const ExtensionRegistry& extension_registry); upb_ExtensionRegistry* registry_; }; + +template > +ABSL_MUST_USE_RESULT bool HasExtension( + Ptr message, + const ::hpb::internal::ExtensionIdentifier& id) { + return ::hpb::internal::HasExtensionOrUnknown( + hpb::interop::upb::GetMessage(message), id.mini_table_ext()); +} + +template > +ABSL_MUST_USE_RESULT bool HasExtension( + const T* message, + const ::hpb::internal::ExtensionIdentifier& id) { + return HasExtension(Ptr(message), id); +} + +template , + typename = hpb::internal::EnableIfMutableProto> +void ClearExtension( + Ptr message, + const ::hpb::internal::ExtensionIdentifier& id) { + static_assert(!std::is_const_v, ""); + upb_Message_ClearExtension(hpb::interop::upb::GetMessage(message), + id.mini_table_ext()); +} + +template > +void ClearExtension( + T* message, const ::hpb::internal::ExtensionIdentifier& id) { + ClearExtension(Ptr(message), id); +} + } // namespace hpb #endif // GOOGLE_PROTOBUF_HPB_EXTENSION_H__ diff --git a/hpb/hpb.h b/hpb/hpb.h index 2faa6d39eb..319d944dfe 100644 --- a/hpb/hpb.h +++ b/hpb/hpb.h @@ -51,41 +51,6 @@ absl::Status SetExtension(upb_Message* message, upb_Arena* message_arena, namespace backend = ::hpb::internal::backend::upb; #endif -template > -ABSL_MUST_USE_RESULT bool HasExtension( - Ptr message, - const ::hpb::internal::ExtensionIdentifier& id) { - return ::hpb::internal::HasExtensionOrUnknown( - hpb::interop::upb::GetMessage(message), id.mini_table_ext()); -} - -template > -ABSL_MUST_USE_RESULT bool HasExtension( - const T* message, - const ::hpb::internal::ExtensionIdentifier& id) { - return HasExtension(Ptr(message), id); -} - -template , - typename = hpb::internal::EnableIfMutableProto> -void ClearExtension( - Ptr message, - const ::hpb::internal::ExtensionIdentifier& id) { - static_assert(!std::is_const_v, ""); - upb_Message_ClearExtension(hpb::interop::upb::GetMessage(message), - id.mini_table_ext()); -} - -template > -void ClearExtension( - T* message, const ::hpb::internal::ExtensionIdentifier& id) { - ClearExtension(Ptr(message), id); -} - template , typename = hpb::internal::EnableIfMutableProto>