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()),