diff --git a/hpb/repeated_field.h b/hpb/repeated_field.h index 7810a043f2..49a60b7550 100644 --- a/hpb/repeated_field.h +++ b/hpb/repeated_field.h @@ -24,7 +24,7 @@ #include "upb/message/copy.h" #include "upb/message/message.h" -namespace protos { +namespace hpb { namespace internal { // Shared implementation of repeated fields for absl::string_view and @@ -296,6 +296,6 @@ class RepeatedField { internal::RepeatedFieldProxy>>; }; -} // namespace protos +} // namespace hpb #endif // PROTOBUF_HPB_REPEATED_FIELD_H_ diff --git a/hpb/repeated_field_iterator.h b/hpb/repeated_field_iterator.h index c6f9f0d46e..19ae699504 100644 --- a/hpb/repeated_field_iterator.h +++ b/hpb/repeated_field_iterator.h @@ -20,7 +20,7 @@ #include "upb/message/array.h" #include "upb/message/message.h" -namespace protos { +namespace hpb { namespace internal { // TODO: Implement std iterator for messages @@ -365,6 +365,6 @@ struct MessageIteratorPolicy { }; } // namespace internal -} // namespace protos +} // namespace hpb #endif // PROTOBUF_HPB_REPEATED_FIELD_ITERATOR_H_ diff --git a/hpb/repeated_field_iterator_test.cc b/hpb/repeated_field_iterator_test.cc index 0e22df4c89..f3ba6efc81 100644 --- a/hpb/repeated_field_iterator_test.cc +++ b/hpb/repeated_field_iterator_test.cc @@ -23,7 +23,7 @@ using ::testing::ElementsAre; -namespace protos { +namespace hpb { namespace internal { template @@ -455,4 +455,4 @@ TEST(StringIteratorTest, IteratorBasedAlgorithmsWork) { } // namespace } // namespace internal -} // namespace protos +} // namespace hpb diff --git a/hpb_generator/gen_repeated_fields.cc b/hpb_generator/gen_repeated_fields.cc index 1b4eef3c5a..78563a6203 100644 --- a/hpb_generator/gen_repeated_fields.cc +++ b/hpb_generator/gen_repeated_fields.cc @@ -12,13 +12,13 @@ #include "google/protobuf/descriptor.pb.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" #include "upb_generator/names.h" @@ -86,8 +86,8 @@ void WriteRepeatedFieldsInMessageHeader(const protobuf::Descriptor* desc, output( R"cc( $1 $2(size_t index) const; - const ::protos::RepeatedField::CProxy $2() const; - ::hpb::Ptr<::protos::RepeatedField<$4>> mutable_$2(); + const ::hpb::RepeatedField::CProxy $2() const; + ::hpb::Ptr<::hpb::RepeatedField<$4>> mutable_$2(); absl::StatusOr<$0> add_$2(); $0 mutable_$2(size_t index) const; )cc", @@ -101,8 +101,8 @@ void WriteRepeatedFieldsInMessageHeader(const protobuf::Descriptor* desc, output( R"cc( $0 $1(size_t index) const; - const ::protos::RepeatedField<$0>::CProxy $1() const; - ::hpb::Ptr<::protos::RepeatedField<$0>> mutable_$1(); + const ::hpb::RepeatedField<$0>::CProxy $1() const; + ::hpb::Ptr<::hpb::RepeatedField<$0>> mutable_$1(); bool add_$1($0 val); void set_$1(size_t index, $0 val); bool resize_$1(size_t len); @@ -112,8 +112,8 @@ void WriteRepeatedFieldsInMessageHeader(const protobuf::Descriptor* desc, output( R"cc( $0 $1(size_t index) const; - const ::protos::RepeatedField<$0>::CProxy $1() const; - ::hpb::Ptr<::protos::RepeatedField<$0>> mutable_$1(); + const ::hpb::RepeatedField<$0>::CProxy $1() const; + ::hpb::Ptr<::hpb::RepeatedField<$0>> mutable_$1(); bool add_$1($0 val); void set_$1(size_t index, $0 val); bool resize_$1(size_t len); @@ -172,15 +172,15 @@ void WriteRepeatedMessageAccessor(const protobuf::Descriptor* message, upbc_name); output( R"cc( - const ::protos::RepeatedField::CProxy $0::$2() const { + const ::hpb::RepeatedField::CProxy $0::$2() const { size_t size; const upb_Array* arr = _$3_$4_$5(msg_, &size); - return ::protos::RepeatedField::CProxy(arr, arena_); + return ::hpb::RepeatedField::CProxy(arr, arena_); }; - ::hpb::Ptr<::protos::RepeatedField<$1>> $0::mutable_$2() { + ::hpb::Ptr<::hpb::RepeatedField<$1>> $0::mutable_$2() { size_t size; upb_Array* arr = _$3_$4_$6(msg_, &size, arena_); - return ::protos::RepeatedField<$1>::Proxy(arr, arena_); + return ::hpb::RepeatedField<$1>::Proxy(arr, arena_); } )cc", class_name, // $0 @@ -238,15 +238,15 @@ void WriteRepeatedStringAccessor(const protobuf::Descriptor* message, MessageName(message), upbc_name); output( R"cc( - const ::protos::RepeatedField<$1>::CProxy $0::$2() const { + const ::hpb::RepeatedField<$1>::CProxy $0::$2() const { size_t size; const upb_Array* arr = _$3_$4_$5(msg_, &size); - return ::protos::RepeatedField<$1>::CProxy(arr, arena_); + return ::hpb::RepeatedField<$1>::CProxy(arr, arena_); }; - ::hpb::Ptr<::protos::RepeatedField<$1>> $0::mutable_$2() { + ::hpb::Ptr<::hpb::RepeatedField<$1>> $0::mutable_$2() { size_t size; upb_Array* arr = _$3_$4_$6(msg_, &size, arena_); - return ::protos::RepeatedField<$1>::Proxy(arr, arena_); + return ::hpb::RepeatedField<$1>::Proxy(arr, arena_); } )cc", class_name, // $0 @@ -302,15 +302,15 @@ void WriteRepeatedScalarAccessor(const protobuf::Descriptor* message, MessageName(message), upbc_name); output( R"cc( - const ::protos::RepeatedField<$1>::CProxy $0::$2() const { + const ::hpb::RepeatedField<$1>::CProxy $0::$2() const { size_t size; const upb_Array* arr = _$3_$4_$5(msg_, &size); - return ::protos::RepeatedField<$1>::CProxy(arr, arena_); + return ::hpb::RepeatedField<$1>::CProxy(arr, arena_); }; - ::hpb::Ptr<::protos::RepeatedField<$1>> $0::mutable_$2() { + ::hpb::Ptr<::hpb::RepeatedField<$1>> $0::mutable_$2() { size_t size; upb_Array* arr = _$3_$4_$6(msg_, &size, arena_); - return ::protos::RepeatedField<$1>::Proxy(arr, arena_); + return ::hpb::RepeatedField<$1>::Proxy(arr, arena_); } )cc", class_name, // $0 diff --git a/hpb_generator/tests/test_generated.cc b/hpb_generator/tests/test_generated.cc index 346f395c90..aa2957eb15 100644 --- a/hpb_generator/tests/test_generated.cc +++ b/hpb_generator/tests/test_generated.cc @@ -433,8 +433,7 @@ TEST(CppGeneratedCode, RepeatedScalarIterator) { test_model.mutable_value_array()->push_back(27); int sum = 0; // Access by value. - const ::protos::RepeatedField::CProxy rep1 = - test_model.value_array(); + const ::hpb::RepeatedField::CProxy rep1 = test_model.value_array(); for (auto i : rep1) { sum += i; } @@ -479,13 +478,13 @@ TEST(CppGeneratedCode, RepeatedScalarIterator) { EXPECT_EQ(it[2], 27); // ValueProxy. sum = 0; - for (::protos::RepeatedField::ValueCProxy c : + for (::hpb::RepeatedField::ValueCProxy c : test_model.value_array()) { sum += c; } EXPECT_EQ(sum, 5 + 16 + 27); sum = 0; - for (::protos::RepeatedField::ValueProxy c : + for (::hpb::RepeatedField::ValueProxy c : *test_model.mutable_value_array()) { sum += c; } diff --git a/protos/repeated_field.h b/protos/repeated_field.h index 9e56db515a..3cc9055264 100644 --- a/protos/repeated_field.h +++ b/protos/repeated_field.h @@ -8,4 +8,7 @@ #ifndef UPB_PROTOS_REPEATED_FIELD_H_ #define UPB_PROTOS_REPEATED_FIELD_H_ #include "google/protobuf/hpb/repeated_field.h" +namespace protos { +using hpb::RepeatedField; +} #endif