diff --git a/hpb/backend/upb/BUILD b/hpb/backend/upb/BUILD index c5b1ce5a0c..e4962b76f4 100644 --- a/hpb/backend/upb/BUILD +++ b/hpb/backend/upb/BUILD @@ -35,9 +35,11 @@ cc_library( deps = [ "//hpb:ptr", "//hpb/internal", + "//upb:base", "//upb:mem", "//upb:message", "//upb:mini_table", + "@com_google_absl//absl/strings:string_view", ], ) diff --git a/hpb/backend/upb/interop.h b/hpb/backend/upb/interop.h index 0ef7b554c8..fee89416a9 100644 --- a/hpb/backend/upb/interop.h +++ b/hpb/backend/upb/interop.h @@ -10,8 +10,10 @@ // The sole public header in hpb/backend/upb +#include "absl/strings/string_view.h" #include "google/protobuf/hpb/internal/internal.h" #include "google/protobuf/hpb/ptr.h" +#include "upb/base/string_view.h" #include "upb/mem/arena.h" #include "upb/message/message.h" #include "upb/mini_table/message.h" @@ -93,6 +95,10 @@ typename T::Proxy MakeHandle(upb_Message* msg, upb_Arena* arena) { return typename T::Proxy(msg, arena); } +inline absl::string_view FromUpbStringView(upb_StringView str) { + return absl::string_view(str.data, str.size); +} + } // namespace hpb::interop::upb #endif // GOOGLE_PROTOBUF_HPB_BACKEND_UPB_INTEROP_H__ diff --git a/hpb/hpb.h b/hpb/hpb.h index 66ed1b6dd7..8186142bf7 100644 --- a/hpb/hpb.h +++ b/hpb/hpb.h @@ -37,11 +37,6 @@ namespace hpb { class ExtensionRegistry; -// TODO: b/354766950 - Move upb-specific chunks out of hpb header -inline absl::string_view UpbStrToStringView(upb_StringView str) { - return absl::string_view(str.data, str.size); -} - // TODO: update bzl and move to upb runtime / protos.cc. inline upb_StringView UpbStrFromStringView(absl::string_view str, upb_Arena* arena) { diff --git a/hpb_generator/gen_accessors.cc b/hpb_generator/gen_accessors.cc index a66870cd30..b201a0bf28 100644 --- a/hpb_generator/gen_accessors.cc +++ b/hpb_generator/gen_accessors.cc @@ -225,7 +225,7 @@ void WriteAccessorsInSource(const protobuf::Descriptor* desc, Output& output) { output( R"cc( $1 $0::$2() const { - return ::hpb::UpbStrToStringView($3_$4(msg_)); + return hpb::interop::upb::FromUpbStringView($3_$4(msg_)); } )cc", class_name, CppConstType(field), resolved_field_name, diff --git a/hpb_generator/gen_repeated_fields.cc b/hpb_generator/gen_repeated_fields.cc index 6e4e02c3c9..0af6b54af6 100644 --- a/hpb_generator/gen_repeated_fields.cc +++ b/hpb_generator/gen_repeated_fields.cc @@ -204,7 +204,7 @@ void WriteRepeatedStringAccessor(const protobuf::Descriptor* message, size_t len; auto* ptr = $3_mutable_$4(msg_, &len); assert(index < len); - return ::hpb::UpbStrToStringView(*(ptr + index)); + return hpb::interop::upb::FromUpbStringView(*(ptr + index)); } )cc", class_name, CppConstType(field), resolved_field_name,