From cb9eff5e85762af98c9bd46bee51cc78ae72416f Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Wed, 20 Nov 2024 14:14:04 -0800 Subject: [PATCH] hpb: Have Parse(T*) delegate to Parse(Ptr) PiperOrigin-RevId: 698517877 --- hpb/hpb.h | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/hpb/hpb.h b/hpb/hpb.h index 3becc509c304..5591f674ac6f 100644 --- a/hpb/hpb.h +++ b/hpb/hpb.h @@ -95,6 +95,11 @@ ABSL_MUST_USE_RESULT bool Parse(Ptr message, absl::string_view bytes) { arena) == kUpb_DecodeStatus_Ok; } +template +ABSL_MUST_USE_RESULT bool Parse(T* message, absl::string_view bytes) { + return Parse(Ptr(message), bytes); +} + template absl::StatusOr Parse(absl::string_view bytes, int options = 0) { T message; @@ -109,19 +114,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,