Skip to content

Commit

Permalink
Abrogate protos::Parse with hpb::Parse
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 667643856
  • Loading branch information
honglooker authored and copybara-github committed Aug 26, 2024
1 parent 9d3391f commit d4fc727
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
3 changes: 1 addition & 2 deletions hpb/internal/message_lock_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ void TestConcurrentExtensionAccess(::hpb::ExtensionRegistry registry) {
::hpb::internal::upb_extension_locker_global.store(&lock_func,
std::memory_order_release);
const std::string payload = GenerateTestData();
TestModel parsed_model =
::protos::Parse<TestModel>(payload, registry).value();
TestModel parsed_model = ::hpb::Parse<TestModel>(payload, registry).value();
const auto test_main = [&] { EXPECT_EQ("str", parsed_model.str1()); };
const auto test_theme = [&] {
ASSERT_TRUE(::hpb::HasExtension(&parsed_model, theme));
Expand Down
18 changes: 9 additions & 9 deletions hpb_generator/tests/test_generated.cc
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ TEST(CppGeneratedCode, SerializeUsingArena) {
::upb::Arena arena;
absl::StatusOr<absl::string_view> bytes = ::hpb::Serialize(&model, arena);
EXPECT_EQ(true, bytes.ok());
TestModel parsed_model = ::protos::Parse<TestModel>(bytes.value()).value();
TestModel parsed_model = ::hpb::Parse<TestModel>(bytes.value()).value();
EXPECT_EQ("Hello World", parsed_model.str1());
}

Expand All @@ -900,7 +900,7 @@ TEST(CppGeneratedCode, SerializeProxyUsingArena) {
absl::StatusOr<absl::string_view> bytes =
::hpb::Serialize(&model_proxy, arena);
EXPECT_EQ(true, bytes.ok());
TestModel parsed_model = ::protos::Parse<TestModel>(bytes.value()).value();
TestModel parsed_model = ::hpb::Parse<TestModel>(bytes.value()).value();
EXPECT_EQ("Hello World", parsed_model.str1());
}

Expand All @@ -911,7 +911,7 @@ TEST(CppGeneratedCode, SerializeNestedMessageUsingArena) {
::hpb::Ptr<const TestModel> child = model.recursive_child();
absl::StatusOr<absl::string_view> bytes = ::hpb::Serialize(child, arena);
EXPECT_EQ(true, bytes.ok());
TestModel parsed_model = ::protos::Parse<TestModel>(bytes.value()).value();
TestModel parsed_model = ::hpb::Parse<TestModel>(bytes.value()).value();
EXPECT_EQ("Hello World", parsed_model.str1());
}

Expand All @@ -924,7 +924,7 @@ TEST(CppGeneratedCode, Parse) {
::upb::Arena arena;
auto bytes = ::hpb::Serialize(&model, arena);
EXPECT_EQ(true, bytes.ok());
TestModel parsed_model = ::protos::Parse<TestModel>(bytes.value()).value();
TestModel parsed_model = ::hpb::Parse<TestModel>(bytes.value()).value();
EXPECT_EQ("Test123", parsed_model.str1());
EXPECT_EQ(true, ::protos::GetExtension(&parsed_model, theme).ok());
}
Expand All @@ -939,7 +939,7 @@ TEST(CppGeneratedCode, ParseIntoPtrToModel) {
auto bytes = ::hpb::Serialize(&model, arena);
EXPECT_EQ(true, bytes.ok());
::hpb::Ptr<TestModel> parsed_model = ::hpb::CreateMessage<TestModel>(arena);
EXPECT_TRUE(::protos::Parse(parsed_model, bytes.value()));
EXPECT_TRUE(::hpb::Parse(parsed_model, bytes.value()));
EXPECT_EQ("Test123", parsed_model->str1());
// Should return an extension even if we don't pass ExtensionRegistry
// by promoting unknown.
Expand All @@ -961,7 +961,7 @@ TEST(CppGeneratedCode, ParseWithExtensionRegistry) {
::hpb::ExtensionRegistry extensions(
{&theme, &other_ext, &ThemeExtension::theme_extension}, arena);
TestModel parsed_model =
::protos::Parse<TestModel>(bytes.value(), extensions).value();
::hpb::Parse<TestModel>(bytes.value(), extensions).value();
EXPECT_EQ("Test123", parsed_model.str1());
EXPECT_EQ(true, ::protos::GetExtension(&parsed_model, theme).ok());
EXPECT_EQ(true, ::protos::GetExtension(&parsed_model,
Expand All @@ -985,14 +985,14 @@ TEST(CppGeneratedCode, SharedPointer) {
std::shared_ptr<TestModel> model = std::make_shared<TestModel>();
::upb::Arena arena;
auto bytes = ::hpb::Serialize(model.get(), arena);
EXPECT_TRUE(::protos::Parse(model.get(), bytes.value()));
EXPECT_TRUE(::hpb::Parse(model.get(), bytes.value()));
}

TEST(CppGeneratedCode, UniquePointer) {
auto model = std::make_unique<TestModel>();
::upb::Arena arena;
auto bytes = ::hpb::Serialize(model.get(), arena);
EXPECT_TRUE(::protos::Parse(model.get(), bytes.value()));
EXPECT_TRUE(::hpb::Parse(model.get(), bytes.value()));
}

TEST(CppGeneratedCode, Assignment) {
Expand Down Expand Up @@ -1224,7 +1224,7 @@ TEST(CppGeneratedCode, HasExtensionAndRegistry) {

// Test with ExtensionRegistry
::hpb::ExtensionRegistry extensions({&theme}, arena);
TestModel parsed_model = ::protos::Parse<TestModel>(data, extensions).value();
TestModel parsed_model = ::hpb::Parse<TestModel>(data, extensions).value();
EXPECT_TRUE(::hpb::HasExtension(&parsed_model, theme));
}

Expand Down
1 change: 0 additions & 1 deletion protos/protos.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ typename T::CProxy CreateMessage(const upb_Message* msg, upb_Arena* arena) {
return hpb::interop::upb::MakeCHandle<T>(msg, arena);
}
} // namespace internal
using hpb::Parse;
using hpb::Serialize;

using hpb::GetExtension;
Expand Down

0 comments on commit d4fc727

Please sign in to comment.