From 28de62f4636ec6c271bf238a205684b8542b8f13 Mon Sep 17 00:00:00 2001 From: Protobuf Team Bot Date: Wed, 8 Feb 2023 09:17:23 -0800 Subject: [PATCH] Add ExtensionRegistry version of Parse to message templates. PiperOrigin-RevId: 508098749 --- protos/protos.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/protos/protos.h b/protos/protos.h index 7b4f423acf..5721a73f78 100644 --- a/protos/protos.h +++ b/protos/protos.h @@ -358,6 +358,17 @@ bool Parse(T& message, absl::string_view bytes) { arena) == kUpb_DecodeStatus_Ok; } +template +bool Parse(T& message, absl::string_view bytes, + const ::protos::ExtensionRegistry& extension_registry) { + _upb_Message_Clear(message.msg(), T::minitable()); + auto* arena = static_cast(message.GetInternalArena()); + return upb_Decode(bytes.data(), bytes.size(), message.msg(), T::minitable(), + /* extreg= */ + ::protos::internal::GetUpbExtensions(extension_registry), + /* options= */ 0, arena) == kUpb_DecodeStatus_Ok; +} + template bool Parse(Ptr& message, absl::string_view bytes) { _upb_Message_Clear(message->msg(), T::minitable()); @@ -367,6 +378,17 @@ bool Parse(Ptr& message, absl::string_view bytes) { arena) == kUpb_DecodeStatus_Ok; } +template +bool Parse(Ptr& message, absl::string_view bytes, + const ::protos::ExtensionRegistry& extension_registry) { + _upb_Message_Clear(message->msg(), T::minitable()); + auto* arena = static_cast(message->GetInternalArena()); + return upb_Decode(bytes.data(), bytes.size(), message->msg(), T::minitable(), + /* extreg= */ + ::protos::internal::GetUpbExtensions(extension_registry), + /* options= */ 0, arena) == kUpb_DecodeStatus_Ok; +} + template bool Parse(std::unique_ptr& message, absl::string_view bytes) { _upb_Message_Clear(message->msg(), T::minitable()); @@ -376,6 +398,17 @@ bool Parse(std::unique_ptr& message, absl::string_view bytes) { arena) == kUpb_DecodeStatus_Ok; } +template +bool Parse(std::unique_ptr& message, absl::string_view bytes, + const ::protos::ExtensionRegistry& extension_registry) { + _upb_Message_Clear(message->msg(), T::minitable()); + auto* arena = static_cast(message->GetInternalArena()); + return upb_Decode(bytes.data(), bytes.size(), message->msg(), T::minitable(), + /* extreg= */ + ::protos::internal::GetUpbExtensions(extension_registry), + /* options= */ 0, arena) == kUpb_DecodeStatus_Ok; +} + template bool Parse(std::shared_ptr& message, absl::string_view bytes) { _upb_Message_Clear(message->msg(), T::minitable()); @@ -385,6 +418,17 @@ bool Parse(std::shared_ptr& message, absl::string_view bytes) { arena) == kUpb_DecodeStatus_Ok; } +template +bool Parse(std::shared_ptr& message, absl::string_view bytes, + const ::protos::ExtensionRegistry& extension_registry) { + _upb_Message_Clear(message->msg(), T::minitable()); + auto* arena = static_cast(message->GetInternalArena()); + return upb_Decode(bytes.data(), bytes.size(), message->msg(), T::minitable(), + /* extreg= */ + ::protos::internal::GetUpbExtensions(extension_registry), + /* options= */ 0, arena) == kUpb_DecodeStatus_Ok; +} + template absl::StatusOr Parse(absl::string_view bytes, int options = 0) { T message;