diff --git a/hpb/extension_lock_test.cc b/hpb/extension_lock_test.cc index 81198082e1..fd9971d60f 100644 --- a/hpb/extension_lock_test.cc +++ b/hpb/extension_lock_test.cc @@ -42,7 +42,7 @@ std::string GenerateTestData() { ABSL_CHECK_OK( ::hpb::SetExtension(&model, ThemeExtension::theme_extension, extension2)); ::upb::Arena arena; - auto bytes = ::protos::Serialize(&model, arena); + auto bytes = ::hpb::Serialize(&model, arena); ABSL_CHECK_OK(bytes); return std::string(bytes->data(), bytes->size()); } @@ -75,7 +75,7 @@ void TestConcurrentExtensionAccess(::hpb::ExtensionRegistry registry) { }; const auto test_serialize = [&] { ::upb::Arena arena; - EXPECT_OK(::protos::Serialize(&parsed_model, arena)); + EXPECT_OK(::hpb::Serialize(&parsed_model, arena)); }; const auto test_copy_constructor = [&] { TestModel copy_a = parsed_model; diff --git a/hpb/hpb.h b/hpb/hpb.h index f6b49f5347..5cd7b9c329 100644 --- a/hpb/hpb.h +++ b/hpb/hpb.h @@ -438,6 +438,12 @@ absl::StatusOr> GetExtension( return GetExtension(Ptr(message), id); } +template +constexpr uint32_t ExtensionNumber( + ::hpb::internal::ExtensionIdentifier id) { + return ::hpb::internal::PrivateAccess::GetExtensionNumber(id); +} + template typename T::Proxy CreateMessage(::hpb::Arena& arena) { return typename T::Proxy(upb_Message_New(T::minitable(), arena.ptr()), @@ -486,17 +492,6 @@ void ClearMessage(hpb::internal::PtrOrRaw message) { upb_Message_Clear(hpb::internal::GetInternalMsg(ptr), minitable); } -} // namespace hpb - -namespace protos { -using hpb::Arena; -using hpb::ExtensionNotFoundError; -using hpb::MessageAllocationError; -using hpb::MessageDecodeError; -using hpb::MessageEncodeError; -using hpb::Ptr; -using hpb::SourceLocation; - template ABSL_MUST_USE_RESULT bool Parse(Ptr message, absl::string_view bytes) { static_assert(!std::is_const_v); @@ -594,12 +589,6 @@ absl::StatusOr Serialize(Ptr message, upb::Arena& arena, arena.ptr(), options); } -template -constexpr uint32_t ExtensionNumber( - ::hpb::internal::ExtensionIdentifier id) { - return ::hpb::internal::PrivateAccess::GetExtensionNumber(id); -} - -} // namespace protos +} // namespace hpb #endif // PROTOBUF_HPB_HPB_H_ diff --git a/hpb_generator/gen_messages.cc b/hpb_generator/gen_messages.cc index de7045aac3..f683c970bd 100644 --- a/hpb_generator/gen_messages.cc +++ b/hpb_generator/gen_messages.cc @@ -15,13 +15,13 @@ #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "absl/strings/string_view.h" -#include "google/protobuf/descriptor.h" #include "google/protobuf/compiler/hpb/gen_accessors.h" #include "google/protobuf/compiler/hpb/gen_enums.h" #include "google/protobuf/compiler/hpb/gen_extensions.h" #include "google/protobuf/compiler/hpb/gen_utils.h" #include "google/protobuf/compiler/hpb/names.h" #include "google/protobuf/compiler/hpb/output.h" +#include "google/protobuf/descriptor.h" #include "upb_generator/common.h" #include "upb_generator/file_layout.h" @@ -217,7 +217,7 @@ void WriteModelPublicDeclaration( // for typetrait checking output("using ExtendableType = $0;\n", ClassName(descriptor)); } - // Note: free function friends that are templates such as ::protos::Parse + // Note: free function friends that are templates such as ::hpb::Parse // require explicit <$2> type parameter in declaration to be able to compile // with gcc otherwise the compiler will fail with // "has not been declared within namespace" error. Even though there is a @@ -246,9 +246,9 @@ void WriteModelPublicDeclaration( friend struct ::hpb::internal::PrivateAccess; friend Proxy; friend CProxy; - friend absl::StatusOr<$2>(::protos::Parse<$2>(absl::string_view bytes, - int options)); - friend absl::StatusOr<$2>(::protos::Parse<$2>( + friend absl::StatusOr<$2>(::hpb::Parse<$2>(absl::string_view bytes, + int options)); + friend absl::StatusOr<$2>(::hpb::Parse<$2>( absl::string_view bytes, const ::hpb::ExtensionRegistry& extension_registry, int options)); friend upb_Arena* ::hpb::internal::GetArena<$0>($0* message); diff --git a/hpb_generator/tests/test_generated.cc b/hpb_generator/tests/test_generated.cc index 4a063e58f2..346f395c90 100644 --- a/hpb_generator/tests/test_generated.cc +++ b/hpb_generator/tests/test_generated.cc @@ -887,7 +887,7 @@ TEST(CppGeneratedCode, SerializeUsingArena) { TestModel model; model.set_str1("Hello World"); ::upb::Arena arena; - absl::StatusOr bytes = ::protos::Serialize(&model, arena); + absl::StatusOr bytes = ::hpb::Serialize(&model, arena); EXPECT_EQ(true, bytes.ok()); TestModel parsed_model = ::protos::Parse(bytes.value()).value(); EXPECT_EQ("Hello World", parsed_model.str1()); @@ -899,7 +899,7 @@ TEST(CppGeneratedCode, SerializeProxyUsingArena) { model_proxy.set_str1("Hello World"); ::upb::Arena arena; absl::StatusOr bytes = - ::protos::Serialize(&model_proxy, arena); + ::hpb::Serialize(&model_proxy, arena); EXPECT_EQ(true, bytes.ok()); TestModel parsed_model = ::protos::Parse(bytes.value()).value(); EXPECT_EQ("Hello World", parsed_model.str1()); @@ -910,7 +910,7 @@ TEST(CppGeneratedCode, SerializeNestedMessageUsingArena) { model.mutable_recursive_child()->set_str1("Hello World"); ::upb::Arena arena; ::hpb::Ptr child = model.recursive_child(); - absl::StatusOr bytes = ::protos::Serialize(child, arena); + absl::StatusOr bytes = ::hpb::Serialize(child, arena); EXPECT_EQ(true, bytes.ok()); TestModel parsed_model = ::protos::Parse(bytes.value()).value(); EXPECT_EQ("Hello World", parsed_model.str1()); @@ -923,7 +923,7 @@ TEST(CppGeneratedCode, Parse) { extension1.set_ext_name("Hello World"); EXPECT_EQ(true, ::hpb::SetExtension(&model, theme, extension1).ok()); ::upb::Arena arena; - auto bytes = ::protos::Serialize(&model, arena); + auto bytes = ::hpb::Serialize(&model, arena); EXPECT_EQ(true, bytes.ok()); TestModel parsed_model = ::protos::Parse(bytes.value()).value(); EXPECT_EQ("Test123", parsed_model.str1()); @@ -937,7 +937,7 @@ TEST(CppGeneratedCode, ParseIntoPtrToModel) { extension1.set_ext_name("Hello World"); EXPECT_EQ(true, ::hpb::SetExtension(&model, theme, extension1).ok()); ::upb::Arena arena; - auto bytes = ::protos::Serialize(&model, arena); + auto bytes = ::hpb::Serialize(&model, arena); EXPECT_EQ(true, bytes.ok()); ::hpb::Ptr parsed_model = ::hpb::CreateMessage(arena); EXPECT_TRUE(::protos::Parse(parsed_model, bytes.value())); @@ -957,7 +957,7 @@ TEST(CppGeneratedCode, ParseWithExtensionRegistry) { extension1) .ok()); ::upb::Arena arena; - auto bytes = ::protos::Serialize(&model, arena); + auto bytes = ::hpb::Serialize(&model, arena); EXPECT_EQ(true, bytes.ok()); ::hpb::ExtensionRegistry extensions( {&theme, &other_ext, &ThemeExtension::theme_extension}, arena); @@ -985,14 +985,14 @@ TEST(CppGeneratedCode, NameCollisions) { TEST(CppGeneratedCode, SharedPointer) { std::shared_ptr model = std::make_shared(); ::upb::Arena arena; - auto bytes = ::protos::Serialize(model.get(), arena); + auto bytes = ::hpb::Serialize(model.get(), arena); EXPECT_TRUE(::protos::Parse(model.get(), bytes.value())); } TEST(CppGeneratedCode, UniquePointer) { auto model = std::make_unique(); ::upb::Arena arena; - auto bytes = ::protos::Serialize(model.get(), arena); + auto bytes = ::hpb::Serialize(model.get(), arena); EXPECT_TRUE(::protos::Parse(model.get(), bytes.value())); } @@ -1221,7 +1221,7 @@ TEST(CppGeneratedCode, HasExtensionAndRegistry) { // Now that we have a source model with extension data, serialize. ::hpb::Arena arena; - std::string data = std::string(::protos::Serialize(&source, arena).value()); + std::string data = std::string(::hpb::Serialize(&source, arena).value()); // Test with ExtensionRegistry ::hpb::ExtensionRegistry extensions({&theme}, arena); diff --git a/protos/protos.h b/protos/protos.h index 4d61918050..2813eaa8b9 100644 --- a/protos/protos.h +++ b/protos/protos.h @@ -29,10 +29,18 @@ using hpb::ClearMessage; using hpb::CloneMessage; using hpb::CreateMessage; using hpb::DeepCopy; +using hpb::Parse; +using hpb::Serialize; using hpb::ClearExtension; +using hpb::ExtensionNotFoundError; +using hpb::ExtensionNumber; using hpb::GetExtension; using hpb::HasExtension; using hpb::SetExtension; + +using hpb::Arena; +using hpb::MessageAllocationError; +using hpb::Ptr; } // namespace protos #endif