From 6ecaefc6288079ea848c96bf2806c09230ad6c67 Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Wed, 9 Oct 2024 11:51:07 -0700 Subject: [PATCH] Move GetExtension and ExtensionNumber from hpb.h to extension.h PiperOrigin-RevId: 684118480 --- hpb/extension.h | 32 ++++++++++++++++++++++++++++++++ hpb/hpb.h | 31 ------------------------------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/hpb/extension.h b/hpb/extension.h index 5ede3f5a60..d5fa632e31 100644 --- a/hpb/extension.h +++ b/hpb/extension.h @@ -16,6 +16,7 @@ #include "google/protobuf/hpb/internal/message_lock.h" #include "google/protobuf/hpb/internal/template_help.h" #include "google/protobuf/hpb/ptr.h" +#include "google/protobuf/hpb/status.h" #include "upb/mem/arena.hpp" #include "upb/mini_table/extension.h" #include "upb/mini_table/extension_registry.h" @@ -205,6 +206,37 @@ absl::Status SetExtension( return ::hpb::SetExtension(Ptr(message), id, value); } +template > +absl::StatusOr> GetExtension( + Ptr message, + const ::hpb::internal::ExtensionIdentifier& id) { + upb_MessageValue value; + const bool ok = ::hpb::internal::GetOrPromoteExtension( + hpb::interop::upb::GetMessage(message), id.mini_table_ext(), + hpb::interop::upb::GetArena(message), &value); + if (!ok) { + return ExtensionNotFoundError( + upb_MiniTableExtension_Number(id.mini_table_ext())); + } + return Ptr(::hpb::interop::upb::MakeCHandle( + (upb_Message*)value.msg_val, hpb::interop::upb::GetArena(message))); +} + +template > +absl::StatusOr> GetExtension( + const T* message, + const ::hpb::internal::ExtensionIdentifier& id) { + return GetExtension(Ptr(message), id); +} + +template +constexpr uint32_t ExtensionNumber( + ::hpb::internal::ExtensionIdentifier id) { + return ::hpb::internal::PrivateAccess::GetExtensionNumber(id); +} + } // namespace hpb #endif // GOOGLE_PROTOBUF_HPB_EXTENSION_H__ diff --git a/hpb/hpb.h b/hpb/hpb.h index 3bdec86824..fbd6ed2f75 100644 --- a/hpb/hpb.h +++ b/hpb/hpb.h @@ -36,37 +36,6 @@ namespace hpb { namespace backend = ::hpb::internal::backend::upb; #endif -template > -absl::StatusOr> GetExtension( - Ptr message, - const ::hpb::internal::ExtensionIdentifier& id) { - upb_MessageValue value; - const bool ok = ::hpb::internal::GetOrPromoteExtension( - hpb::interop::upb::GetMessage(message), id.mini_table_ext(), - hpb::interop::upb::GetArena(message), &value); - if (!ok) { - return ExtensionNotFoundError( - upb_MiniTableExtension_Number(id.mini_table_ext())); - } - return Ptr(::hpb::interop::upb::MakeCHandle( - (upb_Message*)value.msg_val, hpb::interop::upb::GetArena(message))); -} - -template > -absl::StatusOr> GetExtension( - const T* message, - const ::hpb::internal::ExtensionIdentifier& id) { - return GetExtension(Ptr(message), id); -} - -template -constexpr uint32_t ExtensionNumber( - ::hpb::internal::ExtensionIdentifier id) { - return ::hpb::internal::PrivateAccess::GetExtensionNumber(id); -} - template typename T::Proxy CreateMessage(hpb::Arena& arena) { return typename T::Proxy(upb_Message_New(T::minitable(), arena.ptr()),