Open-source generated string_view field methods.

PiperOrigin-RevId: 502028351
pull/11556/head
Mike Kruskal 2 years ago committed by Copybara-Service
parent 232ecf4a6f
commit 0968ecfb7a
  1. 47
      src/google/protobuf/compiler/cpp/field_generators/string_field.cc
  2. 10
      src/google/protobuf/compiler/plugin.pb.h
  3. 40
      src/google/protobuf/descriptor.pb.h

@ -776,12 +776,10 @@ void RepeatedStringFieldGenerator::GenerateAccessorDeclarations(
"$deprecated_attr$void ${1$set_$name$$}$(int index, const "
"char* value);\n",
descriptor_);
if (!options_.opensource_runtime) {
format(
"$deprecated_attr$void ${1$set_$name$$}$(int index, "
"absl::string_view value);\n",
descriptor_);
}
format(
"$deprecated_attr$void ${1$set_$name$$}$(int index, "
"absl::string_view value);\n",
descriptor_);
format(
"$deprecated_attr$void ${1$set_$name$$}$("
"int index, const $pointer_type$* value, ::size_t size);\n"
@ -790,11 +788,8 @@ void RepeatedStringFieldGenerator::GenerateAccessorDeclarations(
"$deprecated_attr$void ${1$add_$name$$}$(std::string&& value);\n"
"$deprecated_attr$void ${1$add_$name$$}$(const char* value);\n",
descriptor_);
if (!options_.opensource_runtime) {
format(
"$deprecated_attr$void ${1$add_$name$$}$(absl::string_view value);\n",
descriptor_);
}
format("$deprecated_attr$void ${1$add_$name$$}$(absl::string_view value);\n",
descriptor_);
format(
"$deprecated_attr$void ${1$add_$name$$}$(const $pointer_type$* "
"value, ::size_t size)"
@ -871,15 +866,13 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
"$annotate_set$"
" // @@protoc_insertion_point(field_set_char:$full_name$)\n"
"}\n");
if (!options_.opensource_runtime) {
format(
"inline void "
"$classname$::set_$name$(int index, absl::string_view value) {\n"
" $field$.Mutable(index)->assign(value.data(), value.size());\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n"
"}\n");
}
format(
"inline void "
"$classname$::set_$name$(int index, absl::string_view value) {\n"
" $field$.Mutable(index)->assign(value.data(), value.size());\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set_string_piece:$full_name$)\n"
"}\n");
format(
"inline void "
"$classname$::set_$name$"
@ -908,14 +901,12 @@ void RepeatedStringFieldGenerator::GenerateInlineAccessorDefinitions(
"$annotate_add$"
" // @@protoc_insertion_point(field_add_char:$full_name$)\n"
"}\n");
if (!options_.opensource_runtime) {
format(
"inline void $classname$::add_$name$(absl::string_view value) {\n"
" $field$.Add()->assign(value.data(), value.size());\n"
"$annotate_add$"
" // @@protoc_insertion_point(field_add_string_piece:$full_name$)\n"
"}\n");
}
format(
"inline void $classname$::add_$name$(absl::string_view value) {\n"
" $field$.Add()->assign(value.data(), value.size());\n"
"$annotate_add$"
" // @@protoc_insertion_point(field_add_string_piece:$full_name$)\n"
"}\n");
format(
"inline void "
"$classname$::add_$name$(const $pointer_type$* value, ::size_t size) {\n"

@ -455,11 +455,13 @@ class PROTOC_EXPORT CodeGeneratorRequest final :
void set_file_to_generate(int index, const std::string& value);
void set_file_to_generate(int index, std::string&& value);
void set_file_to_generate(int index, const char* value);
void set_file_to_generate(int index, absl::string_view value);
void set_file_to_generate(int index, const char* value, ::size_t size);
std::string* add_file_to_generate();
void add_file_to_generate(const std::string& value);
void add_file_to_generate(std::string&& value);
void add_file_to_generate(const char* value);
void add_file_to_generate(absl::string_view value);
void add_file_to_generate(const char* value, ::size_t size);
const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>& file_to_generate() const;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>* mutable_file_to_generate();
@ -1147,6 +1149,10 @@ inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* va
GOOGLE_ABSL_DCHECK(value != nullptr); _impl_.file_to_generate_.Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::set_file_to_generate(int index, absl::string_view value) {
_impl_.file_to_generate_.Mutable(index)->assign(value.data(), value.size());
// @@protoc_insertion_point(field_set_string_piece:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::set_file_to_generate(int index, const char* value, ::size_t size) {
_impl_.file_to_generate_.Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
@ -1167,6 +1173,10 @@ inline void CodeGeneratorRequest::add_file_to_generate(const char* value) {
GOOGLE_ABSL_DCHECK(value != nullptr); _impl_.file_to_generate_.Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::add_file_to_generate(absl::string_view value) {
_impl_.file_to_generate_.Add()->assign(value.data(), value.size());
// @@protoc_insertion_point(field_add_string_piece:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)
}
inline void CodeGeneratorRequest::add_file_to_generate(const char* value, ::size_t size) {
_impl_.file_to_generate_.Add()->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_add_pointer:google.protobuf.compiler.CodeGeneratorRequest.file_to_generate)

@ -729,11 +729,13 @@ class PROTOBUF_EXPORT FileDescriptorProto final :
void set_dependency(int index, const std::string& value);
void set_dependency(int index, std::string&& value);
void set_dependency(int index, const char* value);
void set_dependency(int index, absl::string_view value);
void set_dependency(int index, const char* value, ::size_t size);
std::string* add_dependency();
void add_dependency(const std::string& value);
void add_dependency(std::string&& value);
void add_dependency(const char* value);
void add_dependency(absl::string_view value);
void add_dependency(const char* value, ::size_t size);
const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>& dependency() const;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>* mutable_dependency();
@ -1594,11 +1596,13 @@ class PROTOBUF_EXPORT DescriptorProto final :
void set_reserved_name(int index, const std::string& value);
void set_reserved_name(int index, std::string&& value);
void set_reserved_name(int index, const char* value);
void set_reserved_name(int index, absl::string_view value);
void set_reserved_name(int index, const char* value, ::size_t size);
std::string* add_reserved_name();
void add_reserved_name(const std::string& value);
void add_reserved_name(std::string&& value);
void add_reserved_name(const char* value);
void add_reserved_name(absl::string_view value);
void add_reserved_name(const char* value, ::size_t size);
const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>& reserved_name() const;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>* mutable_reserved_name();
@ -2848,11 +2852,13 @@ class PROTOBUF_EXPORT EnumDescriptorProto final :
void set_reserved_name(int index, const std::string& value);
void set_reserved_name(int index, std::string&& value);
void set_reserved_name(int index, const char* value);
void set_reserved_name(int index, absl::string_view value);
void set_reserved_name(int index, const char* value, ::size_t size);
std::string* add_reserved_name();
void add_reserved_name(const std::string& value);
void add_reserved_name(std::string&& value);
void add_reserved_name(const char* value);
void add_reserved_name(absl::string_view value);
void add_reserved_name(const char* value, ::size_t size);
const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>& reserved_name() const;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>* mutable_reserved_name();
@ -7227,11 +7233,13 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final :
void set_leading_detached_comments(int index, const std::string& value);
void set_leading_detached_comments(int index, std::string&& value);
void set_leading_detached_comments(int index, const char* value);
void set_leading_detached_comments(int index, absl::string_view value);
void set_leading_detached_comments(int index, const char* value, ::size_t size);
std::string* add_leading_detached_comments();
void add_leading_detached_comments(const std::string& value);
void add_leading_detached_comments(std::string&& value);
void add_leading_detached_comments(const char* value);
void add_leading_detached_comments(absl::string_view value);
void add_leading_detached_comments(const char* value, ::size_t size);
const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>& leading_detached_comments() const;
::PROTOBUF_NAMESPACE_ID::RepeatedPtrField<std::string>* mutable_leading_detached_comments();
@ -8079,6 +8087,10 @@ inline void FileDescriptorProto::set_dependency(int index, const char* value) {
GOOGLE_ABSL_DCHECK(value != nullptr); _impl_.dependency_.Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::set_dependency(int index, absl::string_view value) {
_impl_.dependency_.Mutable(index)->assign(value.data(), value.size());
// @@protoc_insertion_point(field_set_string_piece:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::set_dependency(int index, const char* value, ::size_t size) {
_impl_.dependency_.Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
@ -8099,6 +8111,10 @@ inline void FileDescriptorProto::add_dependency(const char* value) {
GOOGLE_ABSL_DCHECK(value != nullptr); _impl_.dependency_.Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::add_dependency(absl::string_view value) {
_impl_.dependency_.Add()->assign(value.data(), value.size());
// @@protoc_insertion_point(field_add_string_piece:google.protobuf.FileDescriptorProto.dependency)
}
inline void FileDescriptorProto::add_dependency(const char* value, ::size_t size) {
_impl_.dependency_.Add()->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_add_pointer:google.protobuf.FileDescriptorProto.dependency)
@ -9335,6 +9351,10 @@ inline void DescriptorProto::set_reserved_name(int index, const char* value) {
GOOGLE_ABSL_DCHECK(value != nullptr); _impl_.reserved_name_.Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::set_reserved_name(int index, absl::string_view value) {
_impl_.reserved_name_.Mutable(index)->assign(value.data(), value.size());
// @@protoc_insertion_point(field_set_string_piece:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::set_reserved_name(int index, const char* value, ::size_t size) {
_impl_.reserved_name_.Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
@ -9355,6 +9375,10 @@ inline void DescriptorProto::add_reserved_name(const char* value) {
GOOGLE_ABSL_DCHECK(value != nullptr); _impl_.reserved_name_.Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::add_reserved_name(absl::string_view value) {
_impl_.reserved_name_.Add()->assign(value.data(), value.size());
// @@protoc_insertion_point(field_add_string_piece:google.protobuf.DescriptorProto.reserved_name)
}
inline void DescriptorProto::add_reserved_name(const char* value, ::size_t size) {
_impl_.reserved_name_.Add()->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_add_pointer:google.protobuf.DescriptorProto.reserved_name)
@ -10427,6 +10451,10 @@ inline void EnumDescriptorProto::set_reserved_name(int index, const char* value)
GOOGLE_ABSL_DCHECK(value != nullptr); _impl_.reserved_name_.Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::set_reserved_name(int index, absl::string_view value) {
_impl_.reserved_name_.Mutable(index)->assign(value.data(), value.size());
// @@protoc_insertion_point(field_set_string_piece:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::set_reserved_name(int index, const char* value, ::size_t size) {
_impl_.reserved_name_.Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
@ -10447,6 +10475,10 @@ inline void EnumDescriptorProto::add_reserved_name(const char* value) {
GOOGLE_ABSL_DCHECK(value != nullptr); _impl_.reserved_name_.Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::add_reserved_name(absl::string_view value) {
_impl_.reserved_name_.Add()->assign(value.data(), value.size());
// @@protoc_insertion_point(field_add_string_piece:google.protobuf.EnumDescriptorProto.reserved_name)
}
inline void EnumDescriptorProto::add_reserved_name(const char* value, ::size_t size) {
_impl_.reserved_name_.Add()->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_add_pointer:google.protobuf.EnumDescriptorProto.reserved_name)
@ -13563,6 +13595,10 @@ inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, co
GOOGLE_ABSL_DCHECK(value != nullptr); _impl_.leading_detached_comments_.Mutable(index)->assign(value);
// @@protoc_insertion_point(field_set_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, absl::string_view value) {
_impl_.leading_detached_comments_.Mutable(index)->assign(value.data(), value.size());
// @@protoc_insertion_point(field_set_string_piece:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::set_leading_detached_comments(int index, const char* value, ::size_t size) {
_impl_.leading_detached_comments_.Mutable(index)->assign(
reinterpret_cast<const char*>(value), size);
@ -13583,6 +13619,10 @@ inline void SourceCodeInfo_Location::add_leading_detached_comments(const char* v
GOOGLE_ABSL_DCHECK(value != nullptr); _impl_.leading_detached_comments_.Add()->assign(value);
// @@protoc_insertion_point(field_add_char:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::add_leading_detached_comments(absl::string_view value) {
_impl_.leading_detached_comments_.Add()->assign(value.data(), value.size());
// @@protoc_insertion_point(field_add_string_piece:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)
}
inline void SourceCodeInfo_Location::add_leading_detached_comments(const char* value, ::size_t size) {
_impl_.leading_detached_comments_.Add()->assign(reinterpret_cast<const char*>(value), size);
// @@protoc_insertion_point(field_add_pointer:google.protobuf.SourceCodeInfo.Location.leading_detached_comments)

Loading…
Cancel
Save