Skip to content

Commit

Permalink
Migrate UpbStrToStringView from hpb to hpb::interop::upb::FromUpbStri…
Browse files Browse the repository at this point in the history
…ngView

PiperOrigin-RevId: 673959164
  • Loading branch information
honglooker authored and copybara-github committed Sep 12, 2024
1 parent c3e7e98 commit 9d835e6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
2 changes: 2 additions & 0 deletions hpb/backend/upb/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
6 changes: 6 additions & 0 deletions hpb/backend/upb/interop.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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__
5 changes: 0 additions & 5 deletions hpb/hpb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion hpb_generator/gen_accessors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion hpb_generator/gen_repeated_fields.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 9d835e6

Please sign in to comment.