Skip to content

Commit

Permalink
hpb: Merge Parse(T*) with Parse(Ptr<T>) by utilizing PtrOrRaw<T>
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 704345856
  • Loading branch information
honglooker authored and copybara-github committed Dec 9, 2024
1 parent 717b5e6 commit 4f98f33
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions hpb/hpb.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <cstdint>
#include <type_traits>

#include "absl/base/attributes.h"
#include "absl/status/statusor.h"
#include "absl/strings/string_view.h"
#include "google/protobuf/hpb/arena.h"
Expand Down Expand Up @@ -83,7 +84,8 @@ void ClearMessage(hpb::internal::PtrOrRaw<T> message) {
}

template <typename T>
ABSL_MUST_USE_RESULT bool Parse(Ptr<T> message, absl::string_view bytes) {
ABSL_MUST_USE_RESULT bool Parse(internal::PtrOrRaw<T> message,
absl::string_view bytes) {
static_assert(!std::is_const_v<T>);
upb_Message_Clear(hpb::interop::upb::GetMessage(message),
::hpb::interop::upb::GetMiniTable(message));
Expand All @@ -109,19 +111,6 @@ absl::StatusOr<T> Parse(absl::string_view bytes, int options = 0) {
return MessageDecodeError(status);
}

template <typename T>
ABSL_MUST_USE_RESULT bool Parse(T* message, absl::string_view bytes) {
static_assert(!std::is_const_v<T>);
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 <typename T>
absl::StatusOr<T> Parse(absl::string_view bytes,
const ::hpb::ExtensionRegistry& extension_registry,
Expand Down

0 comments on commit 4f98f33

Please sign in to comment.