From 9d835e65c622c89643e42fc75207dd56ce3eda27 Mon Sep 17 00:00:00 2001 From: Hong Shin Date: Thu, 12 Sep 2024 12:34:47 -0700 Subject: [PATCH] Migrate UpbStrToStringView from hpb to hpb::interop::upb::FromUpbStringView PiperOrigin-RevId: 673959164 --- hpb/backend/upb/BUILD | 2 ++ hpb/backend/upb/interop.h | 6 ++++++ hpb/hpb.h | 5 ----- hpb_generator/gen_accessors.cc | 2 +- hpb_generator/gen_repeated_fields.cc | 2 +- 5 files changed, 10 insertions(+), 7 deletions(-) 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,