Skip to content

Commit

Permalink
Simplification: remove unused hpb::Parse invocations
Browse files Browse the repository at this point in the history
Too many parseses... like bagginses.. we can expand once the need arises, yess

PiperOrigin-RevId: 698105703
  • Loading branch information
honglooker authored and copybara-github committed Nov 19, 2024
1 parent fe61c44 commit cf46e11
Showing 1 changed file with 11 additions and 35 deletions.
46 changes: 11 additions & 35 deletions hpb/hpb.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,27 +96,17 @@ ABSL_MUST_USE_RESULT bool Parse(Ptr<T> message, absl::string_view bytes) {
}

template <typename T>
ABSL_MUST_USE_RESULT bool Parse(
Ptr<T> message, absl::string_view bytes,
const ::hpb::ExtensionRegistry& extension_registry) {
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= */
::hpb::internal::GetUpbExtensions(extension_registry),
/* options= */ 0, arena) == kUpb_DecodeStatus_Ok;
}

template <typename T>
ABSL_MUST_USE_RESULT bool Parse(
T* message, absl::string_view bytes,
const ::hpb::ExtensionRegistry& extension_registry) {
static_assert(!std::is_const_v<T>);
return Parse(Ptr(message, bytes, extension_registry));
absl::StatusOr<T> Parse(absl::string_view bytes, int options = 0) {
T message;
auto* arena = hpb::interop::upb::GetArena(&message);
upb_DecodeStatus status =
upb_Decode(bytes.data(), bytes.size(), message.msg(),
::hpb::interop::upb::GetMiniTable(&message),
/* extreg= */ nullptr, /* options= */ 0, arena);
if (status == kUpb_DecodeStatus_Ok) {
return message;
}
return MessageDecodeError(status);
}

template <typename T>
Expand All @@ -132,20 +122,6 @@ ABSL_MUST_USE_RESULT bool Parse(T* message, absl::string_view bytes) {
arena) == kUpb_DecodeStatus_Ok;
}

template <typename T>
absl::StatusOr<T> Parse(absl::string_view bytes, int options = 0) {
T message;
auto* arena = hpb::interop::upb::GetArena(&message);
upb_DecodeStatus status =
upb_Decode(bytes.data(), bytes.size(), message.msg(),
::hpb::interop::upb::GetMiniTable(&message),
/* extreg= */ nullptr, /* options= */ 0, arena);
if (status == kUpb_DecodeStatus_Ok) {
return message;
}
return MessageDecodeError(status);
}

template <typename T>
absl::StatusOr<T> Parse(absl::string_view bytes,
const ::hpb::ExtensionRegistry& extension_registry,
Expand Down

0 comments on commit cf46e11

Please sign in to comment.