From 4f98f33ed5e94974310aed4d8463686619165043 Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Mon, 9 Dec 2024 10:55:42 -0800 Subject: [PATCH] hpb: Merge Parse(T*) with Parse(Ptr) by utilizing PtrOrRaw PiperOrigin-RevId: 704345856 --- hpb/hpb.h | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/hpb/hpb.h b/hpb/hpb.h index 3becc509c304b..d101084c7f4f5 100644 --- a/hpb/hpb.h +++ b/hpb/hpb.h @@ -11,6 +11,7 @@ #include #include +#include "absl/base/attributes.h" #include "absl/status/statusor.h" #include "absl/strings/string_view.h" #include "google/protobuf/hpb/arena.h" @@ -83,7 +84,8 @@ void ClearMessage(hpb::internal::PtrOrRaw message) { } template -ABSL_MUST_USE_RESULT bool Parse(Ptr message, absl::string_view bytes) { +ABSL_MUST_USE_RESULT bool Parse(internal::PtrOrRaw message, + absl::string_view bytes) { static_assert(!std::is_const_v); upb_Message_Clear(hpb::interop::upb::GetMessage(message), ::hpb::interop::upb::GetMiniTable(message)); @@ -109,19 +111,6 @@ absl::StatusOr Parse(absl::string_view bytes, int options = 0) { return MessageDecodeError(status); } -template -ABSL_MUST_USE_RESULT bool Parse(T* message, absl::string_view bytes) { - static_assert(!std::is_const_v); - upb_Message_Clear(hpb::interop::upb::GetMessage(message), - ::hpb::interop::upb::GetMiniTable(message)); - auto* arena = hpb::interop::upb::GetArena(message); - return upb_Decode(bytes.data(), bytes.size(), - hpb::interop::upb::GetMessage(message), - ::hpb::interop::upb::GetMiniTable(message), - /* extreg= */ nullptr, /* options= */ 0, - arena) == kUpb_DecodeStatus_Ok; -} - template absl::StatusOr Parse(absl::string_view bytes, const ::hpb::ExtensionRegistry& extension_registry,