Migrate UpbStrToStringView from hpb to hpb::interop::upb::FromUpbStringView

PiperOrigin-RevId: 673959164
pull/18208/head
Hong Shin 3 months ago committed by Copybara-Service
parent c3e7e987fe
commit 9d835e65c6
  1. 2
      hpb/backend/upb/BUILD
  2. 6
      hpb/backend/upb/interop.h
  3. 5
      hpb/hpb.h
  4. 2
      hpb_generator/gen_accessors.cc
  5. 2
      hpb_generator/gen_repeated_fields.cc

@ -35,9 +35,11 @@ cc_library(
deps = [ deps = [
"//hpb:ptr", "//hpb:ptr",
"//hpb/internal", "//hpb/internal",
"//upb:base",
"//upb:mem", "//upb:mem",
"//upb:message", "//upb:message",
"//upb:mini_table", "//upb:mini_table",
"@com_google_absl//absl/strings:string_view",
], ],
) )

@ -10,8 +10,10 @@
// The sole public header in hpb/backend/upb // 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/internal/internal.h"
#include "google/protobuf/hpb/ptr.h" #include "google/protobuf/hpb/ptr.h"
#include "upb/base/string_view.h"
#include "upb/mem/arena.h" #include "upb/mem/arena.h"
#include "upb/message/message.h" #include "upb/message/message.h"
#include "upb/mini_table/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); 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 } // namespace hpb::interop::upb
#endif // GOOGLE_PROTOBUF_HPB_BACKEND_UPB_INTEROP_H__ #endif // GOOGLE_PROTOBUF_HPB_BACKEND_UPB_INTEROP_H__

@ -37,11 +37,6 @@
namespace hpb { namespace hpb {
class ExtensionRegistry; 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. // TODO: update bzl and move to upb runtime / protos.cc.
inline upb_StringView UpbStrFromStringView(absl::string_view str, inline upb_StringView UpbStrFromStringView(absl::string_view str,
upb_Arena* arena) { upb_Arena* arena) {

@ -225,7 +225,7 @@ void WriteAccessorsInSource(const protobuf::Descriptor* desc, Output& output) {
output( output(
R"cc( R"cc(
$1 $0::$2() const { $1 $0::$2() const {
return ::hpb::UpbStrToStringView($3_$4(msg_)); return hpb::interop::upb::FromUpbStringView($3_$4(msg_));
} }
)cc", )cc",
class_name, CppConstType(field), resolved_field_name, class_name, CppConstType(field), resolved_field_name,

@ -204,7 +204,7 @@ void WriteRepeatedStringAccessor(const protobuf::Descriptor* message,
size_t len; size_t len;
auto* ptr = $3_mutable_$4(msg_, &len); auto* ptr = $3_mutable_$4(msg_, &len);
assert(index < len); assert(index < len);
return ::hpb::UpbStrToStringView(*(ptr + index)); return hpb::interop::upb::FromUpbStringView(*(ptr + index));
} }
)cc", )cc",
class_name, CppConstType(field), resolved_field_name, class_name, CppConstType(field), resolved_field_name,

Loading…
Cancel
Save