Use FieldDescriptor.cpp_string_type() instead of CType directly.

PiperOrigin-RevId: 692198493
pull/19098/head
Protobuf Team Bot 5 months ago committed by Copybara-Service
parent 51e2664f2f
commit a27f0c79d4
  1. 17
      src/google/protobuf/compiler/rust/accessors/accessors.cc
  2. 7
      src/google/protobuf/compiler/rust/accessors/with_presence.cc
  3. 4
      src/google/protobuf/compiler/rust/oneof.cc

@ -27,14 +27,14 @@ namespace {
std::unique_ptr<AccessorGenerator> AccessorGeneratorFor(
Context& ctx, const FieldDescriptor& field) {
// TODO: We do not support ctype=CORD fields or repeated
// ctype=STRING_PIECE fields on cpp kernel yet (upb doesn't care about ctype).
auto ctype = field.options().ctype();
if (ctx.is_cpp() &&
(ctype == FieldOptions::CORD || ctype == FieldOptions::STRING_PIECE) &&
field.is_repeated()) {
// TODO: We do not support repeated strings on C++ kernel if
// they are not string_view or string type.
if (ctx.is_cpp() && field.is_repeated() &&
field.cpp_type() == FieldDescriptor::CPPTYPE_STRING &&
field.cpp_string_type() != FieldDescriptor::CppStringType::kView &&
field.cpp_string_type() != FieldDescriptor::CppStringType::kString) {
return std::make_unique<UnsupportedField>(
"fields has an unsupported ctype");
"unsupported repeated string type");
}
if (field.is_map()) {
@ -57,7 +57,8 @@ std::unique_ptr<AccessorGenerator> AccessorGeneratorFor(
return std::make_unique<SingularScalar>();
case RustFieldType::BYTES:
case RustFieldType::STRING:
if (ctype == FieldOptions::CORD) {
if (ctx.is_cpp() &&
field.cpp_string_type() == FieldDescriptor::CppStringType::kCord) {
return std::make_unique<SingularCord>();
}
return std::make_unique<SingularString>();

@ -83,7 +83,12 @@ void WithPresenceAccessorsInMsgImpl(Context& ctx, const FieldDescriptor& field,
{"opt_getter",
[&] {
// Cord fields don't support the _opt getter.
if (field.options().ctype() == FieldOptions::CORD) return;
if (ctx.is_cpp() &&
field.cpp_type() == FieldDescriptor::CPPTYPE_STRING &&
field.cpp_string_type() ==
FieldDescriptor::CppStringType::kCord) {
return;
}
ctx.Emit(
R"rs(
pub fn $raw_field_name$_opt($view_self$) -> $pb$::Optional<$view_type$> {

@ -83,7 +83,9 @@ namespace rust {
namespace {
// A user-friendly rust type for a view of this field with lifetime 'msg.
std::string RsTypeNameView(Context& ctx, const FieldDescriptor& field) {
if (field.options().has_ctype()) {
if (ctx.is_cpp() && field.cpp_type() == FieldDescriptor::CPPTYPE_STRING &&
field.cpp_string_type() != FieldDescriptor::CppStringType::kView &&
field.cpp_string_type() != FieldDescriptor::CppStringType::kString) {
return ""; // TODO: b/308792377 - ctype fields not supported yet.
}
switch (GetRustFieldType(field.type())) {

Loading…
Cancel
Save