Refactor enum_field.cc to use Emit().

PiperOrigin-RevId: 508418812
pull/11603/head
Protobuf Team Bot 2 years ago committed by Copybara-Service
parent ecbca635d8
commit 7f6f12240f
  1. 17
      src/google/protobuf/compiler/cpp/field.cc
  2. 787
      src/google/protobuf/compiler/cpp/field_generators/enum_field.cc
  3. 4
      src/google/protobuf/compiler/cpp/field_generators/generators.h
  4. 2
      src/google/protobuf/compiler/cpp/field_generators/primitive_field.cc
  5. 117
      src/google/protobuf/descriptor.pb.cc
  6. 144
      src/google/protobuf/descriptor.pb.h

@ -39,10 +39,8 @@
#include <string>
#include <vector>
#include "google/protobuf/descriptor.h"
#include "absl/container/flat_hash_map.h"
#include "absl/log/absl_check.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
@ -50,6 +48,7 @@
#include "google/protobuf/compiler/cpp/helpers.h"
#include "google/protobuf/compiler/cpp/options.h"
#include "google/protobuf/compiler/cpp/tracker.h"
#include "google/protobuf/descriptor.h"
#include "google/protobuf/descriptor.pb.h"
#include "google/protobuf/io/printer.h"
#include "google/protobuf/wire_format.h"
@ -172,17 +171,9 @@ std::unique_ptr<FieldGeneratorBase> MakeGenerator(const FieldDescriptor* field,
}
}
if (field->real_containing_oneof()) {
switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_MESSAGE:
return MakeOneofMessageGenerator(field, options, scc);
case FieldDescriptor::CPPTYPE_STRING:
return MakeSinguarStringGenerator(field, options, scc);
case FieldDescriptor::CPPTYPE_ENUM:
return MakeOneofEnumGenerator(field, options, scc);
default:
return MakeSinguarPrimitiveGenerator(field, options, scc);
}
if (field->real_containing_oneof() &&
field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) {
return MakeOneofMessageGenerator(field, options, scc);
}
switch (field->cpp_type()) {

@ -35,10 +35,12 @@
#include <memory>
#include <string>
#include <tuple>
#include <vector>
#include "absl/container/flat_hash_map.h"
#include "absl/log/absl_check.h"
#include "absl/memory/memory.h"
#include "absl/strings/substitute.h"
#include "google/protobuf/compiler/cpp/field.h"
#include "google/protobuf/compiler/cpp/field_generators/generators.h"
#include "google/protobuf/compiler/cpp/helpers.h"
@ -49,475 +51,418 @@ namespace protobuf {
namespace compiler {
namespace cpp {
namespace {
void SetEnumVariables(
const FieldDescriptor* descriptor,
absl::flat_hash_map<absl::string_view, std::string>* variables,
const Options& options) {
const EnumValueDescriptor* default_value = descriptor->default_value_enum();
(*variables)["type"] = QualifiedClassName(descriptor->enum_type(), options);
(*variables)["default"] = Int32ToString(default_value->number());
(*variables)["full_name"] = descriptor->full_name();
(*variables)["cached_byte_size_name"] = MakeVarintCachedSizeName(descriptor);
bool cold = ShouldSplit(descriptor, options);
(*variables)["cached_byte_size_field"] =
MakeVarintCachedSizeFieldName(descriptor, cold);
}
class EnumFieldGenerator : public FieldGeneratorBase {
public:
EnumFieldGenerator(const FieldDescriptor* descriptor, const Options& options);
~EnumFieldGenerator() override = default;
void GeneratePrivateMembers(io::Printer* printer) const override;
void GenerateAccessorDeclarations(io::Printer* printer) const override;
void GenerateInlineAccessorDefinitions(io::Printer* printer) const override;
void GenerateClearingCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override {}
void GenerateCopyConstructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateConstexprAggregateInitializer(
io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
};
class EnumOneofFieldGenerator : public EnumFieldGenerator {
using Sub = ::google::protobuf::io::Printer::Sub;
std::vector<Sub> Vars(const FieldDescriptor* field, const Options& opts) {
const EnumValueDescriptor* default_value = field->default_value_enum();
bool split = ShouldSplit(field, opts);
bool is_open = internal::cpp::HasPreservingUnknownEnumSemantics(field);
auto enum_name = QualifiedClassName(field->enum_type(), opts);
return {
{"Enum", enum_name},
{"kDefault", Int32ToString(default_value->number())},
Sub("assert_valid",
is_open ? ""
: absl::Substitute("assert($0_IsValid(value));", enum_name))
.WithSuffix(";"),
{"cached_size_name", MakeVarintCachedSizeName(field)},
{"cached_size_", MakeVarintCachedSizeFieldName(field, split)},
};
}
class SingularEnum : public FieldGeneratorBase {
public:
EnumOneofFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
~EnumOneofFieldGenerator() override = default;
void GenerateInlineAccessorDefinitions(io::Printer* printer) const override;
void GenerateClearingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
};
class RepeatedEnumFieldGenerator : public FieldGeneratorBase {
public:
RepeatedEnumFieldGenerator(const FieldDescriptor* descriptor,
const Options& options);
~RepeatedEnumFieldGenerator() override = default;
// implements FieldGeneratorBase ---------------------------------------
void GeneratePrivateMembers(io::Printer* printer) const override;
void GenerateAccessorDeclarations(io::Printer* printer) const override;
void GenerateInlineAccessorDefinitions(io::Printer* printer) const override;
void GenerateClearingCode(io::Printer* printer) const override;
void GenerateMergingCode(io::Printer* printer) const override;
void GenerateSwappingCode(io::Printer* printer) const override;
void GenerateConstructorCode(io::Printer* printer) const override;
void GenerateCopyConstructorCode(io::Printer* /*printer*/) const override {
ABSL_CHECK(!ShouldSplit(descriptor_, options_));
SingularEnum(const FieldDescriptor* field, const Options& opts)
: FieldGeneratorBase(field, opts),
field_(field),
opts_(&opts),
is_oneof_(field->real_containing_oneof() != nullptr) {}
~SingularEnum() override = default;
std::vector<Sub> MakeVars() const override { return Vars(field_, *opts_); }
void GeneratePrivateMembers(io::Printer* p) const override {
p->Emit(R"cc(
int $name$_;
)cc");
}
void GenerateDestructorCode(io::Printer* printer) const override;
void GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const override;
void GenerateByteSize(io::Printer* printer) const override;
void GenerateConstexprAggregateInitializer(
io::Printer* printer) const override;
void GenerateAggregateInitializer(io::Printer* printer) const override;
void GenerateCopyAggregateInitializer(io::Printer* printer) const override;
};
// ===================================================================
EnumFieldGenerator::EnumFieldGenerator(const FieldDescriptor* descriptor,
const Options& options)
: FieldGeneratorBase(descriptor, options) {
SetEnumVariables(descriptor, &variables_, options);
}
void EnumFieldGenerator::GeneratePrivateMembers(io::Printer* printer) const {
Formatter format(printer, variables_);
format("int $name$_;\n");
}
void EnumFieldGenerator::GenerateAccessorDeclarations(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$deprecated_attr$$type$ ${1$$name$$}$() const;\n", descriptor_);
format("$deprecated_attr$void ${1$set_$name$$}$($type$ value);\n",
std::make_tuple(descriptor_, GeneratedCodeInfo::Annotation::SET));
format(
"private:\n"
"$type$ ${1$_internal_$name$$}$() const;\n"
"void ${1$_internal_set_$name$$}$($type$ value);\n"
"public:\n",
descriptor_);
}
void EnumFieldGenerator::GenerateInlineAccessorDefinitions(
io::Printer* printer) const {
Formatter format(printer, variables_);
format(
"inline $type$ $classname$::_internal_$name$() const {\n"
" return static_cast< $type$ >($field$);\n"
"}\n"
"inline $type$ $classname$::$name$() const {\n"
"$annotate_get$"
" // @@protoc_insertion_point(field_get:$full_name$)\n"
" return _internal_$name$();\n"
"}\n"
"inline void $classname$::_internal_set_$name$($type$ value) {\n");
if (!internal::cpp::HasPreservingUnknownEnumSemantics(descriptor_)) {
format(" assert($type$_IsValid(value));\n");
void GenerateClearingCode(io::Printer* p) const override {
p->Emit(R"cc(
$field_$ = $kDefault$;
)cc");
}
format(
" $set_hasbit$\n"
" $field$ = value;\n"
"}\n"
"inline void $classname$::set_$name$($type$ value) {\n"
"$maybe_prepare_split_message$"
" _internal_set_$name$(value);\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n");
}
void EnumFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field$ = $default$;\n");
}
void EnumFieldGenerator::GenerateMergingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
format("_this->_internal_set_$name$(from._internal_$name$());\n");
}
void EnumFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
format("swap($field$, other->$field$);\n");
}
void EnumFieldGenerator::GenerateCopyConstructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("_this->$field$ = from.$field$;\n");
}
void EnumFieldGenerator::GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const {
Formatter format(printer, variables_);
format(
"target = stream->EnsureSpace(target);\n"
"target = ::_pbi::WireFormatLite::WriteEnumToArray(\n"
" $number$, this->_internal_$name$(), target);\n");
}
void EnumFieldGenerator::GenerateByteSize(io::Printer* printer) const {
Formatter format(printer, variables_);
format(
"total_size += $tag_size$ +\n"
" ::_pbi::WireFormatLite::EnumSize(this->_internal_$name$());\n");
}
void GenerateMergingCode(io::Printer* p) const override {
p->Emit(R"cc(
_this->_internal_set_$name$(from._internal_$name$());
)cc");
}
void EnumFieldGenerator::GenerateConstexprAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("/*decltype($field$)*/$default$");
}
void GenerateSwappingCode(io::Printer* p) const override {
if (is_oneof_) return;
void EnumFieldGenerator::GenerateAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
if (ShouldSplit(descriptor_, options_)) {
format("decltype(Impl_::Split::$name$_){$default$}");
return;
p->Emit(R"cc(
swap($field_$, other->$field_$);
)cc");
}
format("decltype($field$){$default$}");
}
void EnumFieldGenerator::GenerateCopyAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("decltype($field$){}");
}
void GenerateConstructorCode(io::Printer* p) const override {
if (!is_oneof_) return;
p->Emit(R"cc(
$ns$::_$Msg$_default_instance_.$field_$ = $kDefault$;
)cc");
}
// ===================================================================
void GenerateCopyConstructorCode(io::Printer* p) const override {
p->Emit(R"cc(
_this->$field_$ = from.$field_$;
)cc");
}
EnumOneofFieldGenerator::EnumOneofFieldGenerator(
const FieldDescriptor* descriptor, const Options& options)
: EnumFieldGenerator(descriptor, options) {
}
void GenerateSerializeWithCachedSizesToArray(io::Printer* p) const override {
p->Emit(R"cc(
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
$number$, this->_internal_$name$(), target);
)cc");
}
void EnumOneofFieldGenerator::GenerateInlineAccessorDefinitions(
io::Printer* printer) const {
Formatter format(printer, variables_);
format(
"inline $type$ $classname$::_internal_$name$() const {\n"
" if ($has_field$) {\n"
" return static_cast< $type$ >($field$);\n"
" }\n"
" return static_cast< $type$ >($default$);\n"
"}\n"
"inline $type$ $classname$::$name$() const {\n"
"$annotate_get$"
" // @@protoc_insertion_point(field_get:$full_name$)\n"
" return _internal_$name$();\n"
"}\n"
"inline void $classname$::_internal_set_$name$($type$ value) {\n");
if (!internal::cpp::HasPreservingUnknownEnumSemantics(descriptor_)) {
format(" assert($type$_IsValid(value));\n");
void GenerateByteSize(io::Printer* p) const override {
p->Emit(R"cc(
total_size += $kTagBytes$ +
::_pbi::WireFormatLite::EnumSize(this->_internal_$name$());
)cc");
}
format(
" if ($not_has_field$) {\n"
" clear_$oneof_name$();\n"
" set_has_$name$();\n"
" }\n"
" $field$ = value;\n"
"}\n"
"inline void $classname$::set_$name$($type$ value) {\n"
" _internal_set_$name$(value);\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n");
}
void EnumOneofFieldGenerator::GenerateClearingCode(io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field$ = $default$;\n");
}
void GenerateConstexprAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc(
/*decltype($field_$)*/ $kDefault$
)cc");
}
void EnumOneofFieldGenerator::GenerateSwappingCode(io::Printer* printer) const {
// Don't print any swapping code. Swapping the union will swap this field.
}
void GenerateAggregateInitializer(io::Printer* p) const override {
if (ShouldSplit(descriptor_, options_)) {
p->Emit(R"cc(
decltype(Impl_::Split::$name$_) { $kDefault$ }
)cc");
return;
}
p->Emit(R"cc(
decltype($field_$) { $kDefault$ }
)cc");
}
void EnumOneofFieldGenerator::GenerateConstructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$ns$::_$classname$_default_instance_.$field$ = $default$;\n");
}
void GenerateCopyAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc(
decltype($field_$) {}
)cc");
}
// ===================================================================
void GenerateAccessorDeclarations(io::Printer* p) const override;
void GenerateInlineAccessorDefinitions(io::Printer* p) const override;
RepeatedEnumFieldGenerator::RepeatedEnumFieldGenerator(
const FieldDescriptor* descriptor, const Options& options)
: FieldGeneratorBase(descriptor, options) {
SetEnumVariables(descriptor, &variables_, options);
}
private:
const FieldDescriptor* field_;
const Options* opts_;
bool is_oneof_;
};
void RepeatedEnumFieldGenerator::GeneratePrivateMembers(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("::$proto_ns$::RepeatedField<int> $name$_;\n");
if (descriptor_->is_packed() &&
HasGeneratedMethods(descriptor_->file(), options_)) {
format(
"mutable ::$proto_ns$::internal::CachedSize "
"$cached_byte_size_name$;\n");
void SingularEnum::GenerateAccessorDeclarations(io::Printer* p) const {
auto v = p->WithVars(
AnnotatedAccessors(field_, {"", "set_", "_internal_", "_internal_set_"}));
p->Emit(R"cc(
$DEPRECATED$ $Enum$ $name$() const;
$DEPRECATED$ void $set_name$($Enum$ value);
private:
$Enum$ $_internal_name$() const;
void $_internal_set_name$($Enum$ value);
public:
)cc");
}
void SingularEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const {
p->Emit(R"cc(
inline $Enum$ $Msg$::$name$() const {
$annotate_get$;
// @@protoc_insertion_point(field_get:$pkg.Msg.field$)
return _internal_$name$();
}
inline void $Msg$::set_$name$($Enum$ value) {
$maybe_prepare_split_message$ _internal_set_$name$(value);
$annotate_set$;
// @@protoc_insertion_point(field_set:$pkg.Msg.field$)
}
)cc");
if (is_oneof_) {
p->Emit(R"cc(
inline $Enum$ $Msg$::_internal_$name$() const {
if ($has_field$) {
return static_cast<$Enum$>($field_$);
}
return static_cast<$Enum$>($kDefault$);
}
inline void $Msg$::_internal_set_$name$($Enum$ value) {
$assert_valid$;
if ($not_has_field$) {
clear_$oneof_name$();
set_has_$name$();
}
$field_$ = value;
}
)cc");
} else {
p->Emit(R"cc(
inline $Enum$ $Msg$::_internal_$name$() const {
return static_cast<$Enum$>($field_$);
}
inline void $Msg$::_internal_set_$name$($Enum$ value) {
$assert_valid$;
$set_hasbit$;
$field_$ = value;
}
)cc");
}
}
void RepeatedEnumFieldGenerator::GenerateAccessorDeclarations(
io::Printer* printer) const {
Formatter format(printer, variables_);
format(
"private:\n"
"$type$ ${1$_internal_$name$$}$(int index) const;\n"
"void ${1$_internal_add_$name$$}$($type$ value);\n"
"::$proto_ns$::RepeatedField<int>* "
"${1$_internal_mutable_$name$$}$();\n"
"public:\n"
"$deprecated_attr$$type$ ${1$$name$$}$(int index) const;\n"
"$deprecated_attr$void ${1$set_$name$$}$(int index, $type$ value);\n"
"$deprecated_attr$void ${1$add_$name$$}$($type$ value);\n"
"$deprecated_attr$const ::$proto_ns$::RepeatedField<int>& "
"${1$$name$$}$() const;\n"
"$deprecated_attr$::$proto_ns$::RepeatedField<int>* "
"${1$mutable_$name$$}$();\n",
descriptor_);
}
void RepeatedEnumFieldGenerator::GenerateInlineAccessorDefinitions(
io::Printer* printer) const {
Formatter format(printer, variables_);
format(
"inline $type$ $classname$::_internal_$name$(int index) const {\n"
" return static_cast< $type$ >($field$.Get(index));\n"
"}\n"
"inline $type$ $classname$::$name$(int index) const {\n"
"$annotate_get$"
" // @@protoc_insertion_point(field_get:$full_name$)\n"
" return _internal_$name$(index);\n"
"}\n"
"inline void $classname$::set_$name$(int index, $type$ value) {\n");
if (!internal::cpp::HasPreservingUnknownEnumSemantics(descriptor_)) {
format(" assert($type$_IsValid(value));\n");
}
format(
" $field$.Set(index, value);\n"
"$annotate_set$"
" // @@protoc_insertion_point(field_set:$full_name$)\n"
"}\n"
"inline void $classname$::_internal_add_$name$($type$ value) {\n");
if (!internal::cpp::HasPreservingUnknownEnumSemantics(descriptor_)) {
format(" assert($type$_IsValid(value));\n");
class RepeatedEnum : public FieldGeneratorBase {
public:
RepeatedEnum(const FieldDescriptor* field, const Options& opts)
: FieldGeneratorBase(field, opts),
field_(field),
opts_(&opts),
has_cached_size_(field_->is_packed() &&
HasGeneratedMethods(field_->file(), opts)) {}
~RepeatedEnum() override = default;
std::vector<Sub> MakeVars() const override { return Vars(field_, *opts_); }
void GeneratePrivateMembers(io::Printer* p) const override {
p->Emit(R"cc(
$pb$::RepeatedField<int> $name$_;
)cc");
if (has_cached_size_) {
p->Emit(R"cc(
mutable $pbi$::CachedSize $cached_size_name$;
)cc");
}
}
format(
" $field$.Add(value);\n"
"}\n"
"inline void $classname$::add_$name$($type$ value) {\n"
" _internal_add_$name$(value);\n"
"$annotate_add$"
" // @@protoc_insertion_point(field_add:$full_name$)\n"
"}\n"
"inline const ::$proto_ns$::RepeatedField<int>&\n"
"$classname$::$name$() const {\n"
"$annotate_list$"
" // @@protoc_insertion_point(field_list:$full_name$)\n"
" return $field$;\n"
"}\n"
"inline ::$proto_ns$::RepeatedField<int>*\n"
"$classname$::_internal_mutable_$name$() {\n"
" return &$field$;\n"
"}\n"
"inline ::$proto_ns$::RepeatedField<int>*\n"
"$classname$::mutable_$name$() {\n"
"$annotate_mutable_list$"
" // @@protoc_insertion_point(field_mutable_list:$full_name$)\n"
" return _internal_mutable_$name$();\n"
"}\n");
}
void RepeatedEnumFieldGenerator::GenerateClearingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field$.Clear();\n");
}
void RepeatedEnumFieldGenerator::GenerateMergingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("_this->$field$.MergeFrom(from.$field$);\n");
}
void GenerateClearingCode(io::Printer* p) const override {
p->Emit(R"cc(
$field_$.Clear();
)cc");
}
void RepeatedEnumFieldGenerator::GenerateSwappingCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field$.InternalSwap(&other->$field$);\n");
}
void GenerateMergingCode(io::Printer* p) const override {
p->Emit(R"cc(
_this->$field_$.MergeFrom(from.$field_$);
)cc");
}
void RepeatedEnumFieldGenerator::GenerateConstructorCode(
io::Printer* printer) const {
// Not needed for repeated fields.
}
void GenerateSwappingCode(io::Printer* p) const override {
p->Emit(R"cc(
$field_$.InternalSwap(&other->$field_$);
)cc");
}
void RepeatedEnumFieldGenerator::GenerateDestructorCode(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("$field$.~RepeatedField();\n");
}
void GenerateDestructorCode(io::Printer* p) const override {
p->Emit(R"cc(
$field_$.~RepeatedField();
)cc");
}
void RepeatedEnumFieldGenerator::GenerateSerializeWithCachedSizesToArray(
io::Printer* printer) const {
Formatter format(printer, variables_);
if (descriptor_->is_packed()) {
// Write the tag and the size.
format(
"{\n"
" int byte_size = "
"$cached_byte_size_field$.Get();\n"
" if (byte_size > 0) {\n"
" target = stream->WriteEnumPacked(\n"
" $number$, $field$, byte_size, target);\n"
" }\n"
"}\n");
} else {
format(
"for (int i = 0, n = this->_internal_$name$_size(); i < n; i++) {\n"
" target = stream->EnsureSpace(target);\n"
" target = ::_pbi::WireFormatLite::WriteEnumToArray(\n"
" $number$, this->_internal_$name$(i), target);\n"
"}\n");
void GenerateConstexprAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc(
/*decltype($field_$)*/ {}
)cc");
if (has_cached_size_) {
p->Emit(R"cc(
, /*decltype($cached_size_$)*/ { 0 }
)cc");
}
}
}
void RepeatedEnumFieldGenerator::GenerateByteSize(io::Printer* printer) const {
Formatter format(printer, variables_);
format(
"{\n"
" ::size_t data_size = 0;\n"
" unsigned int count = static_cast<unsigned "
"int>(this->_internal_$name$_size());");
format.Indent();
format(
"for (unsigned int i = 0; i < count; i++) {\n"
" data_size += ::_pbi::WireFormatLite::EnumSize(\n"
" this->_internal_$name$(static_cast<int>(i)));\n"
"}\n");
if (descriptor_->is_packed()) {
format(
"if (data_size > 0) {\n"
" total_size += $tag_size$ +\n"
" "
"::_pbi::WireFormatLite::Int32Size(static_cast<$int32$>(data_size));\n"
"}\n"
"int cached_size = ::_pbi::ToCachedSize(data_size);\n"
"$cached_byte_size_field$.Set(cached_size);\n"
"total_size += data_size;\n");
} else {
format("total_size += ($tag_size$UL * count) + data_size;\n");
void GenerateAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc(
decltype($field_$) { arena }
)cc");
if (has_cached_size_) {
// std::atomic has no copy constructor, which prevents explicit aggregate
// initialization pre-C++17.
p->Emit(R"cc(
, /*decltype($cached_size_$)*/ { 0 }
)cc");
}
}
format.Outdent();
format("}\n");
}
void RepeatedEnumFieldGenerator::GenerateConstexprAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("/*decltype($field$)*/{}");
if (descriptor_->is_packed() &&
HasGeneratedMethods(descriptor_->file(), options_)) {
format("\n, /*decltype($cached_byte_size_field$)*/{0}");
void GenerateCopyAggregateInitializer(io::Printer* p) const override {
p->Emit(R"cc(
decltype($field_$) { from.$field_$ })cc");
if (has_cached_size_) {
// std::atomic has no copy constructor.
p->Emit(R"cc(
, /*decltype($cached_size_$)*/ { 0 }
)cc");
}
}
}
void RepeatedEnumFieldGenerator::GenerateAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("decltype($field$){arena}");
if (descriptor_->is_packed() &&
HasGeneratedMethods(descriptor_->file(), options_)) {
// std::atomic has no copy constructor, which prevents explicit aggregate
// initialization pre-C++17.
format("\n, /*decltype($cached_byte_size_field$)*/{0}");
void GenerateCopyConstructorCode(io::Printer* p) const override {
ABSL_CHECK(!ShouldSplit(field_, *opts_));
}
}
void RepeatedEnumFieldGenerator::GenerateCopyAggregateInitializer(
io::Printer* printer) const {
Formatter format(printer, variables_);
format("decltype($field$){from.$field$}");
if (descriptor_->is_packed() &&
HasGeneratedMethods(descriptor_->file(), options_)) {
// std::atomic has no copy constructor.
format("\n, /*decltype($cached_byte_size_field$)*/{0}");
void GenerateConstructorCode(io::Printer* p) const override {}
void GenerateAccessorDeclarations(io::Printer* p) const override;
void GenerateInlineAccessorDefinitions(io::Printer* p) const override;
void GenerateSerializeWithCachedSizesToArray(io::Printer* p) const override;
void GenerateByteSize(io::Printer* p) const override;
private:
const FieldDescriptor* field_;
const Options* opts_;
bool has_cached_size_;
};
void RepeatedEnum::GenerateAccessorDeclarations(io::Printer* p) const {
auto v = p->WithVars(
AnnotatedAccessors(field_, {"", "set_", "add_", "mutable_", "_internal_",
"_internal_add_", "_internal_mutable_"}));
p->Emit(R"cc(
public:
$DEPRECATED$ $Enum$ $name$(int index) const;
$DEPRECATED$ void $set_name$(int index, $Enum$ value);
$DEPRECATED$ void $add_name$($Enum$ value);
$DEPRECATED$ const $pb$::RepeatedField<int>& $name$() const;
$DEPRECATED$ $pb$::RepeatedField<int>* $mutable_name$();
private:
$Enum$ $_internal_name$(int index) const;
void $_internal_add_name$($Enum$ value);
$pb$::RepeatedField<int>* $_internal_mutable_name$();
public:
)cc");
}
void RepeatedEnum::GenerateInlineAccessorDefinitions(io::Printer* p) const {
p->Emit(R"cc(
inline $Enum$ $Msg$::$name$(int index) const {
$annotate_get$;
// @@protoc_insertion_point(field_get:$pkg.Msg.field$)
return _internal_$name$(index);
}
inline void $Msg$::set_$name$(int index, $Enum$ value) {
$assert_valid$;
$field_$.Set(index, value);
$annotate_set$
// @@protoc_insertion_point(field_set:$pkg.Msg.field$)
}
inline void $Msg$::add_$name$($Enum$ value) {
_internal_add_$name$(value);
$annotate_add$
// @@protoc_insertion_point(field_add:$pkg.Msg.field$)
}
inline const $pb$::RepeatedField<int>& $Msg$::$name$() const {
$annotate_list$;
// @@protoc_insertion_point(field_list:$pkg.Msg.field$)
return $field_$;
}
inline $pb$::RepeatedField<int>* $Msg$::mutable_$name$() {
$annotate_mutable_list$;
// @@protoc_insertion_point(field_mutable_list:$pkg.Msg.field$)
return _internal_mutable_$name$();
}
inline $Enum$ $Msg$::_internal_$name$(int index) const {
return static_cast<$Enum$>($field_$.Get(index));
}
inline void $Msg$::_internal_add_$name$($Enum$ value) {
$assert_valid$;
$field_$.Add(value);
}
inline $pb$::RepeatedField<int>* $Msg$::_internal_mutable_$name$() {
return &$field_$;
}
)cc");
}
void RepeatedEnum::GenerateSerializeWithCachedSizesToArray(
io::Printer* p) const {
if (field_->is_packed()) {
p->Emit(R"cc(
{
int byte_size = $cached_size_$.Get();
if (byte_size > 0) {
target = stream->WriteEnumPacked($number$, $field_$, byte_size, target);
}
}
)cc");
return;
}
p->Emit(R"cc(
for (int i = 0, n = this->_internal_$name$_size(); i < n; ++i) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
$number$, this->_internal_$name$(i), target);
}
)cc");
}
void RepeatedEnum::GenerateByteSize(io::Printer* p) const {
p->Emit(
{
{"add_to_size",
[&] {
if (!field_->is_packed()) {
p->Emit(R"cc(
total_size += std::size_t{$kTagBytes$} * count;
)cc");
return;
}
p->Emit(R"cc(
if (data_size > 0) {
total_size += $kTagBytes$;
total_size += ::_pbi::WireFormatLite::Int32Size(
static_cast<int32_t>(data_size));
}
$cached_size_$.Set(::_pbi::ToCachedSize(data_size));
)cc");
}},
},
R"cc(
{
std::size_t data_size = 0;
auto count = static_cast<std::size_t>(this->_internal_$name$_size());
for (std::size_t i = 0; i < count; ++i) {
data_size += ::_pbi::WireFormatLite::EnumSize(
this->_internal_$name$(static_cast<int>(i)));
}
total_size += data_size;
$add_to_size$;
}
)cc");
}
} // namespace
std::unique_ptr<FieldGeneratorBase> MakeSinguarEnumGenerator(
const FieldDescriptor* desc, const Options& options,
MessageSCCAnalyzer* scc) {
return absl::make_unique<EnumFieldGenerator>(desc, options);
return absl::make_unique<SingularEnum>(desc, options);
}
std::unique_ptr<FieldGeneratorBase> MakeRepeatedEnumGenerator(
const FieldDescriptor* desc, const Options& options,
MessageSCCAnalyzer* scc) {
return absl::make_unique<RepeatedEnumFieldGenerator>(desc, options);
}
std::unique_ptr<FieldGeneratorBase> MakeOneofEnumGenerator(
const FieldDescriptor* desc, const Options& options,
MessageSCCAnalyzer* scc) {
return absl::make_unique<EnumOneofFieldGenerator>(desc, options);
return absl::make_unique<RepeatedEnum>(desc, options);
}
} // namespace cpp

@ -67,10 +67,6 @@ std::unique_ptr<FieldGeneratorBase> MakeRepeatedEnumGenerator(
const FieldDescriptor* desc, const Options& options,
MessageSCCAnalyzer* scc);
std::unique_ptr<FieldGeneratorBase> MakeOneofEnumGenerator(
const FieldDescriptor* desc, const Options& options,
MessageSCCAnalyzer* scc);
std::unique_ptr<FieldGeneratorBase> MakeSinguarStringGenerator(
const FieldDescriptor* desc, const Options& options,
MessageSCCAnalyzer* scc);

@ -37,11 +37,9 @@
#include <tuple>
#include <vector>
#include "google/protobuf/descriptor.h"
#include "absl/container/flat_hash_map.h"
#include "absl/log/absl_log.h"
#include "absl/memory/memory.h"
#include "absl/strings/substitute.h"
#include "absl/types/optional.h"
#include "google/protobuf/compiler/cpp/field_generators/generators.h"
#include "google/protobuf/compiler/cpp/helpers.h"

@ -184,8 +184,10 @@ PROTOBUF_CONSTEXPR FieldDescriptorProto::FieldDescriptorProto(
, /*decltype(_impl_.proto3_optional_)*/ false
, /*decltype(_impl_.label_)*/1
, /*decltype(_impl_.type_)*/1} {}
, /*decltype(_impl_.label_)*/ 1
, /*decltype(_impl_.type_)*/ 1
} {}
struct FieldDescriptorProtoDefaultTypeInternal {
PROTOBUF_CONSTEXPR FieldDescriptorProtoDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {}
~FieldDescriptorProtoDefaultTypeInternal() {}
@ -389,7 +391,8 @@ PROTOBUF_CONSTEXPR FileOptions::FileOptions(
, /*decltype(_impl_.deprecated_)*/ false
, /*decltype(_impl_.optimize_for_)*/1
, /*decltype(_impl_.optimize_for_)*/ 1
, /*decltype(_impl_.cc_enable_arenas_)*/ true
} {}
struct FileOptionsDefaultTypeInternal {
@ -434,8 +437,10 @@ PROTOBUF_CONSTEXPR FieldOptions::FieldOptions(
, /*decltype(_impl_._has_bits_)*/{}
, /*decltype(_impl_._cached_size_)*/{}
, /*decltype(_impl_.uninterpreted_option_)*/{}
, /*decltype(_impl_.ctype_)*/0
, /*decltype(_impl_.jstype_)*/0
, /*decltype(_impl_.ctype_)*/ 0
, /*decltype(_impl_.jstype_)*/ 0
, /*decltype(_impl_.packed_)*/ false
, /*decltype(_impl_.lazy_)*/ false
@ -448,8 +453,10 @@ PROTOBUF_CONSTEXPR FieldOptions::FieldOptions(
, /*decltype(_impl_.debug_redact_)*/ false
, /*decltype(_impl_.retention_)*/0
, /*decltype(_impl_.target_)*/0} {}
, /*decltype(_impl_.retention_)*/ 0
, /*decltype(_impl_.target_)*/ 0
} {}
struct FieldOptionsDefaultTypeInternal {
PROTOBUF_CONSTEXPR FieldOptionsDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {}
~FieldOptionsDefaultTypeInternal() {}
@ -541,7 +548,8 @@ PROTOBUF_CONSTEXPR MethodOptions::MethodOptions(
, /*decltype(_impl_.uninterpreted_option_)*/{}
, /*decltype(_impl_.deprecated_)*/ false
, /*decltype(_impl_.idempotency_level_)*/0} {}
, /*decltype(_impl_.idempotency_level_)*/ 0
} {}
struct MethodOptionsDefaultTypeInternal {
PROTOBUF_CONSTEXPR MethodOptionsDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {}
~MethodOptionsDefaultTypeInternal() {}
@ -663,7 +671,8 @@ PROTOBUF_CONSTEXPR GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(
, /*decltype(_impl_.end_)*/ 0
, /*decltype(_impl_.semantic_)*/0} {}
, /*decltype(_impl_.semantic_)*/ 0
} {}
struct GeneratedCodeInfo_AnnotationDefaultTypeInternal {
PROTOBUF_CONSTEXPR GeneratedCodeInfo_AnnotationDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {}
~GeneratedCodeInfo_AnnotationDefaultTypeInternal() {}
@ -4033,8 +4042,10 @@ FieldDescriptorProto::FieldDescriptorProto(const FieldDescriptorProto& from)
, decltype(_impl_.proto3_optional_) {}
, decltype(_impl_.label_){}
, decltype(_impl_.type_){}};
, decltype(_impl_.label_) {}
, decltype(_impl_.type_) {}
};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
_impl_.name_.InitDefault();
@ -4103,8 +4114,10 @@ inline void FieldDescriptorProto::SharedCtor(::_pb::Arena* arena) {
, decltype(_impl_.proto3_optional_) { false }
, decltype(_impl_.label_){1}
, decltype(_impl_.type_){1}
, decltype(_impl_.label_) { 1 }
, decltype(_impl_.type_) { 1 }
};
_impl_.name_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
@ -4390,14 +4403,14 @@ failure:
if (cached_has_bits & 0x00000200u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
4, this->_internal_label(), target);
4, this->_internal_label(), target);
}
// optional .google.protobuf.FieldDescriptorProto.Type type = 5;
if (cached_has_bits & 0x00000400u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
5, this->_internal_type(), target);
5, this->_internal_type(), target);
}
// optional string type_name = 6;
@ -4522,13 +4535,13 @@ failure:
// optional .google.protobuf.FieldDescriptorProto.Label label = 4;
if (cached_has_bits & 0x00000200u) {
total_size += 1 +
::_pbi::WireFormatLite::EnumSize(this->_internal_label());
::_pbi::WireFormatLite::EnumSize(this->_internal_label());
}
// optional .google.protobuf.FieldDescriptorProto.Type type = 5;
if (cached_has_bits & 0x00000400u) {
total_size += 1 +
::_pbi::WireFormatLite::EnumSize(this->_internal_type());
::_pbi::WireFormatLite::EnumSize(this->_internal_type());
}
}
@ -6716,7 +6729,8 @@ FileOptions::FileOptions(const FileOptions& from)
, decltype(_impl_.deprecated_) {}
, decltype(_impl_.optimize_for_){}
, decltype(_impl_.optimize_for_) {}
, decltype(_impl_.cc_enable_arenas_) {}
};
@ -6841,7 +6855,8 @@ inline void FileOptions::SharedCtor(::_pb::Arena* arena) {
, decltype(_impl_.deprecated_) { false }
, decltype(_impl_.optimize_for_){1}
, decltype(_impl_.optimize_for_) { 1 }
, decltype(_impl_.cc_enable_arenas_) { true }
};
@ -7286,7 +7301,7 @@ failure:
if (cached_has_bits & 0x00040000u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
9, this->_internal_optimize_for(), target);
9, this->_internal_optimize_for(), target);
}
// optional bool java_multiple_files = 10 [default = false];
@ -7562,7 +7577,7 @@ failure:
// optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED];
if (cached_has_bits & 0x00040000u) {
total_size += 1 +
::_pbi::WireFormatLite::EnumSize(this->_internal_optimize_for());
::_pbi::WireFormatLite::EnumSize(this->_internal_optimize_for());
}
// optional bool cc_enable_arenas = 31 [default = true];
@ -8171,8 +8186,10 @@ FieldOptions::FieldOptions(const FieldOptions& from)
, decltype(_impl_._has_bits_){from._impl_._has_bits_}
, /*decltype(_impl_._cached_size_)*/{}
, decltype(_impl_.uninterpreted_option_){from._impl_.uninterpreted_option_}
, decltype(_impl_.ctype_){}
, decltype(_impl_.jstype_){}
, decltype(_impl_.ctype_) {}
, decltype(_impl_.jstype_) {}
, decltype(_impl_.packed_) {}
, decltype(_impl_.lazy_) {}
@ -8185,8 +8202,10 @@ FieldOptions::FieldOptions(const FieldOptions& from)
, decltype(_impl_.debug_redact_) {}
, decltype(_impl_.retention_){}
, decltype(_impl_.target_){}};
, decltype(_impl_.retention_) {}
, decltype(_impl_.target_) {}
};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
_impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_);
@ -8203,8 +8222,10 @@ inline void FieldOptions::SharedCtor(::_pb::Arena* arena) {
, decltype(_impl_._has_bits_){}
, /*decltype(_impl_._cached_size_)*/{}
, decltype(_impl_.uninterpreted_option_){arena}
, decltype(_impl_.ctype_){0}
, decltype(_impl_.jstype_){0}
, decltype(_impl_.ctype_) { 0 }
, decltype(_impl_.jstype_) { 0 }
, decltype(_impl_.packed_) { false }
, decltype(_impl_.lazy_) { false }
@ -8217,8 +8238,10 @@ inline void FieldOptions::SharedCtor(::_pb::Arena* arena) {
, decltype(_impl_.debug_redact_) { false }
, decltype(_impl_.retention_){0}
, decltype(_impl_.target_){0}
, decltype(_impl_.retention_) { 0 }
, decltype(_impl_.target_) { 0 }
};
}
@ -8441,7 +8464,7 @@ failure:
if (cached_has_bits & 0x00000001u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
1, this->_internal_ctype(), target);
1, this->_internal_ctype(), target);
}
// optional bool packed = 2;
@ -8469,7 +8492,7 @@ failure:
if (cached_has_bits & 0x00000002u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
6, this->_internal_jstype(), target);
6, this->_internal_jstype(), target);
}
// optional bool weak = 10 [default = false];
@ -8497,14 +8520,14 @@ failure:
if (cached_has_bits & 0x00000100u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
17, this->_internal_retention(), target);
17, this->_internal_retention(), target);
}
// optional .google.protobuf.FieldOptions.OptionTargetType target = 18;
if (cached_has_bits & 0x00000200u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
18, this->_internal_target(), target);
18, this->_internal_target(), target);
}
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
@ -8549,13 +8572,13 @@ failure:
// optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING];
if (cached_has_bits & 0x00000001u) {
total_size += 1 +
::_pbi::WireFormatLite::EnumSize(this->_internal_ctype());
::_pbi::WireFormatLite::EnumSize(this->_internal_ctype());
}
// optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];
if (cached_has_bits & 0x00000002u) {
total_size += 1 +
::_pbi::WireFormatLite::EnumSize(this->_internal_jstype());
::_pbi::WireFormatLite::EnumSize(this->_internal_jstype());
}
// optional bool packed = 2;
@ -8593,13 +8616,13 @@ failure:
// optional .google.protobuf.FieldOptions.OptionRetention retention = 17;
if (cached_has_bits & 0x00000100u) {
total_size += 2 +
::_pbi::WireFormatLite::EnumSize(this->_internal_retention());
::_pbi::WireFormatLite::EnumSize(this->_internal_retention());
}
// optional .google.protobuf.FieldOptions.OptionTargetType target = 18;
if (cached_has_bits & 0x00000200u) {
total_size += 2 +
::_pbi::WireFormatLite::EnumSize(this->_internal_target());
::_pbi::WireFormatLite::EnumSize(this->_internal_target());
}
}
@ -9772,7 +9795,8 @@ MethodOptions::MethodOptions(const MethodOptions& from)
, decltype(_impl_.uninterpreted_option_){from._impl_.uninterpreted_option_}
, decltype(_impl_.deprecated_) {}
, decltype(_impl_.idempotency_level_){}};
, decltype(_impl_.idempotency_level_) {}
};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
_impl_._extensions_.MergeFrom(internal_default_instance(), from._impl_._extensions_);
@ -9791,7 +9815,8 @@ inline void MethodOptions::SharedCtor(::_pb::Arena* arena) {
, decltype(_impl_.uninterpreted_option_){arena}
, decltype(_impl_.deprecated_) { false }
, decltype(_impl_.idempotency_level_){0}
, decltype(_impl_.idempotency_level_) { 0 }
};
}
@ -9924,7 +9949,7 @@ failure:
if (cached_has_bits & 0x00000002u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
34, this->_internal_idempotency_level(), target);
34, this->_internal_idempotency_level(), target);
}
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
@ -9974,7 +9999,7 @@ failure:
// optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN];
if (cached_has_bits & 0x00000002u) {
total_size += 2 +
::_pbi::WireFormatLite::EnumSize(this->_internal_idempotency_level());
::_pbi::WireFormatLite::EnumSize(this->_internal_idempotency_level());
}
}
@ -11422,7 +11447,8 @@ GeneratedCodeInfo_Annotation::GeneratedCodeInfo_Annotation(const GeneratedCodeIn
, decltype(_impl_.end_) {}
, decltype(_impl_.semantic_){}};
, decltype(_impl_.semantic_) {}
};
_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_);
_impl_.source_file_.InitDefault();
@ -11452,7 +11478,8 @@ inline void GeneratedCodeInfo_Annotation::SharedCtor(::_pb::Arena* arena) {
, decltype(_impl_.end_) { 0 }
, decltype(_impl_.semantic_){0}
, decltype(_impl_.semantic_) { 0 }
};
_impl_.source_file_.InitDefault();
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
@ -11631,7 +11658,7 @@ failure:
if (cached_has_bits & 0x00000008u) {
target = stream->EnsureSpace(target);
target = ::_pbi::WireFormatLite::WriteEnumToArray(
5, this->_internal_semantic(), target);
5, this->_internal_semantic(), target);
}
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
@ -11686,7 +11713,7 @@ failure:
// optional .google.protobuf.GeneratedCodeInfo.Annotation.Semantic semantic = 5;
if (cached_has_bits & 0x00000008u) {
total_size += 1 +
::_pbi::WireFormatLite::EnumSize(this->_internal_semantic());
::_pbi::WireFormatLite::EnumSize(this->_internal_semantic());
}
}

@ -2439,18 +2439,22 @@ class PROTOBUF_EXPORT FieldDescriptorProto final :
void clear_label() ;
::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label label() const;
void set_label(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label value);
private:
::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label _internal_label() const;
void _internal_set_label(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label value);
public:
// optional .google.protobuf.FieldDescriptorProto.Type type = 5;
bool has_type() const;
void clear_type() ;
::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type type() const;
void set_type(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type value);
private:
::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type _internal_type() const;
void _internal_set_type(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type value);
public:
// @@protoc_insertion_point(class_scope:google.protobuf.FieldDescriptorProto)
private:
@ -4225,9 +4229,11 @@ class PROTOBUF_EXPORT FileOptions final :
void clear_optimize_for() ;
::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode optimize_for() const;
void set_optimize_for(::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode value);
private:
::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode _internal_optimize_for() const;
void _internal_set_optimize_for(::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode value);
public:
// optional bool cc_enable_arenas = 31 [default = true];
bool has_cc_enable_arenas() const;
@ -5063,18 +5069,22 @@ class PROTOBUF_EXPORT FieldOptions final :
void clear_ctype() ;
::PROTOBUF_NAMESPACE_ID::FieldOptions_CType ctype() const;
void set_ctype(::PROTOBUF_NAMESPACE_ID::FieldOptions_CType value);
private:
::PROTOBUF_NAMESPACE_ID::FieldOptions_CType _internal_ctype() const;
void _internal_set_ctype(::PROTOBUF_NAMESPACE_ID::FieldOptions_CType value);
public:
// optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL];
bool has_jstype() const;
void clear_jstype() ;
::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType jstype() const;
void set_jstype(::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType value);
private:
::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType _internal_jstype() const;
void _internal_set_jstype(::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType value);
public:
// optional bool packed = 2;
bool has_packed() const;
@ -5147,18 +5157,22 @@ class PROTOBUF_EXPORT FieldOptions final :
void clear_retention() ;
::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention retention() const;
void set_retention(::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention value);
private:
::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention _internal_retention() const;
void _internal_set_retention(::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention value);
public:
// optional .google.protobuf.FieldOptions.OptionTargetType target = 18;
bool has_target() const;
void clear_target() ;
::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType target() const;
void set_target(::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType value);
private:
::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType _internal_target() const;
void _internal_set_target(::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType value);
public:
template <typename _proto_TypeTraits, ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type,
bool _is_packed>
@ -6853,9 +6867,11 @@ class PROTOBUF_EXPORT MethodOptions final :
void clear_idempotency_level() ;
::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel idempotency_level() const;
void set_idempotency_level(::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel value);
private:
::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel _internal_idempotency_level() const;
void _internal_set_idempotency_level(::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel value);
public:
template <typename _proto_TypeTraits, ::PROTOBUF_NAMESPACE_ID::internal::FieldType _field_type,
bool _is_packed>
@ -8134,9 +8150,11 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final :
void clear_semantic() ;
::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic semantic() const;
void set_semantic(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic value);
private:
::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic _internal_semantic() const;
void _internal_set_semantic(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic value);
public:
// @@protoc_insertion_point(class_scope:google.protobuf.GeneratedCodeInfo.Annotation)
private:
@ -9999,22 +10017,22 @@ inline void FieldDescriptorProto::clear_label() {
_impl_.label_ = 1;
_impl_._has_bits_[0] &= ~0x00000200u;
}
inline ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label FieldDescriptorProto::_internal_label() const {
return static_cast< ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label >(_impl_.label_);
}
inline ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label FieldDescriptorProto::label() const {
// @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.label)
return _internal_label();
}
inline void FieldDescriptorProto::set_label(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label value) {
_internal_set_label(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.label)
}
inline ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label FieldDescriptorProto::_internal_label() const {
return static_cast<::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label>(_impl_.label_);
}
inline void FieldDescriptorProto::_internal_set_label(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label value) {
assert(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label_IsValid(value));
_impl_._has_bits_[0] |= 0x00000200u;
_impl_.label_ = value;
}
inline void FieldDescriptorProto::set_label(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Label value) {
_internal_set_label(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.label)
}
// optional .google.protobuf.FieldDescriptorProto.Type type = 5;
inline bool FieldDescriptorProto::has_type() const {
@ -10025,22 +10043,22 @@ inline void FieldDescriptorProto::clear_type() {
_impl_.type_ = 1;
_impl_._has_bits_[0] &= ~0x00000400u;
}
inline ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type FieldDescriptorProto::_internal_type() const {
return static_cast< ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type >(_impl_.type_);
}
inline ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type FieldDescriptorProto::type() const {
// @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.type)
return _internal_type();
}
inline void FieldDescriptorProto::set_type(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type value) {
_internal_set_type(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.type)
}
inline ::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type FieldDescriptorProto::_internal_type() const {
return static_cast<::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type>(_impl_.type_);
}
inline void FieldDescriptorProto::_internal_set_type(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type value) {
assert(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type_IsValid(value));
_impl_._has_bits_[0] |= 0x00000400u;
_impl_.type_ = value;
}
inline void FieldDescriptorProto::set_type(::PROTOBUF_NAMESPACE_ID::FieldDescriptorProto_Type value) {
_internal_set_type(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldDescriptorProto.type)
}
// optional string type_name = 6;
inline bool FieldDescriptorProto::has_type_name() const {
@ -11896,22 +11914,22 @@ inline void FileOptions::clear_optimize_for() {
_impl_.optimize_for_ = 1;
_impl_._has_bits_[0] &= ~0x00040000u;
}
inline ::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode FileOptions::_internal_optimize_for() const {
return static_cast< ::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode >(_impl_.optimize_for_);
}
inline ::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode FileOptions::optimize_for() const {
// @@protoc_insertion_point(field_get:google.protobuf.FileOptions.optimize_for)
return _internal_optimize_for();
}
inline void FileOptions::set_optimize_for(::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode value) {
_internal_set_optimize_for(value);
// @@protoc_insertion_point(field_set:google.protobuf.FileOptions.optimize_for)
}
inline ::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode FileOptions::_internal_optimize_for() const {
return static_cast<::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode>(_impl_.optimize_for_);
}
inline void FileOptions::_internal_set_optimize_for(::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode value) {
assert(::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode_IsValid(value));
_impl_._has_bits_[0] |= 0x00040000u;
_impl_.optimize_for_ = value;
}
inline void FileOptions::set_optimize_for(::PROTOBUF_NAMESPACE_ID::FileOptions_OptimizeMode value) {
_internal_set_optimize_for(value);
// @@protoc_insertion_point(field_set:google.protobuf.FileOptions.optimize_for)
}
// optional string go_package = 11;
inline bool FileOptions::has_go_package() const {
@ -12805,22 +12823,22 @@ inline void FieldOptions::clear_ctype() {
_impl_.ctype_ = 0;
_impl_._has_bits_[0] &= ~0x00000001u;
}
inline ::PROTOBUF_NAMESPACE_ID::FieldOptions_CType FieldOptions::_internal_ctype() const {
return static_cast< ::PROTOBUF_NAMESPACE_ID::FieldOptions_CType >(_impl_.ctype_);
}
inline ::PROTOBUF_NAMESPACE_ID::FieldOptions_CType FieldOptions::ctype() const {
// @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.ctype)
return _internal_ctype();
}
inline void FieldOptions::set_ctype(::PROTOBUF_NAMESPACE_ID::FieldOptions_CType value) {
_internal_set_ctype(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.ctype)
}
inline ::PROTOBUF_NAMESPACE_ID::FieldOptions_CType FieldOptions::_internal_ctype() const {
return static_cast<::PROTOBUF_NAMESPACE_ID::FieldOptions_CType>(_impl_.ctype_);
}
inline void FieldOptions::_internal_set_ctype(::PROTOBUF_NAMESPACE_ID::FieldOptions_CType value) {
assert(::PROTOBUF_NAMESPACE_ID::FieldOptions_CType_IsValid(value));
_impl_._has_bits_[0] |= 0x00000001u;
_impl_.ctype_ = value;
}
inline void FieldOptions::set_ctype(::PROTOBUF_NAMESPACE_ID::FieldOptions_CType value) {
_internal_set_ctype(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.ctype)
}
// optional bool packed = 2;
inline bool FieldOptions::has_packed() const {
@ -12856,22 +12874,22 @@ inline void FieldOptions::clear_jstype() {
_impl_.jstype_ = 0;
_impl_._has_bits_[0] &= ~0x00000002u;
}
inline ::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType FieldOptions::_internal_jstype() const {
return static_cast< ::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType >(_impl_.jstype_);
}
inline ::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType FieldOptions::jstype() const {
// @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.jstype)
return _internal_jstype();
}
inline void FieldOptions::set_jstype(::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType value) {
_internal_set_jstype(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.jstype)
}
inline ::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType FieldOptions::_internal_jstype() const {
return static_cast<::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType>(_impl_.jstype_);
}
inline void FieldOptions::_internal_set_jstype(::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType value) {
assert(::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType_IsValid(value));
_impl_._has_bits_[0] |= 0x00000002u;
_impl_.jstype_ = value;
}
inline void FieldOptions::set_jstype(::PROTOBUF_NAMESPACE_ID::FieldOptions_JSType value) {
_internal_set_jstype(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.jstype)
}
// optional bool lazy = 5 [default = false];
inline bool FieldOptions::has_lazy() const {
@ -13007,22 +13025,22 @@ inline void FieldOptions::clear_retention() {
_impl_.retention_ = 0;
_impl_._has_bits_[0] &= ~0x00000100u;
}
inline ::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention FieldOptions::_internal_retention() const {
return static_cast< ::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention >(_impl_.retention_);
}
inline ::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention FieldOptions::retention() const {
// @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.retention)
return _internal_retention();
}
inline void FieldOptions::set_retention(::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention value) {
_internal_set_retention(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.retention)
}
inline ::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention FieldOptions::_internal_retention() const {
return static_cast<::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention>(_impl_.retention_);
}
inline void FieldOptions::_internal_set_retention(::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention value) {
assert(::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention_IsValid(value));
_impl_._has_bits_[0] |= 0x00000100u;
_impl_.retention_ = value;
}
inline void FieldOptions::set_retention(::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionRetention value) {
_internal_set_retention(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.retention)
}
// optional .google.protobuf.FieldOptions.OptionTargetType target = 18;
inline bool FieldOptions::has_target() const {
@ -13033,22 +13051,22 @@ inline void FieldOptions::clear_target() {
_impl_.target_ = 0;
_impl_._has_bits_[0] &= ~0x00000200u;
}
inline ::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType FieldOptions::_internal_target() const {
return static_cast< ::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType >(_impl_.target_);
}
inline ::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType FieldOptions::target() const {
// @@protoc_insertion_point(field_get:google.protobuf.FieldOptions.target)
return _internal_target();
}
inline void FieldOptions::set_target(::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType value) {
_internal_set_target(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.target)
}
inline ::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType FieldOptions::_internal_target() const {
return static_cast<::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType>(_impl_.target_);
}
inline void FieldOptions::_internal_set_target(::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType value) {
assert(::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType_IsValid(value));
_impl_._has_bits_[0] |= 0x00000200u;
_impl_.target_ = value;
}
inline void FieldOptions::set_target(::PROTOBUF_NAMESPACE_ID::FieldOptions_OptionTargetType value) {
_internal_set_target(value);
// @@protoc_insertion_point(field_set:google.protobuf.FieldOptions.target)
}
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
inline int FieldOptions::_internal_uninterpreted_option_size() const {
@ -13429,22 +13447,22 @@ inline void MethodOptions::clear_idempotency_level() {
_impl_.idempotency_level_ = 0;
_impl_._has_bits_[0] &= ~0x00000002u;
}
inline ::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel MethodOptions::_internal_idempotency_level() const {
return static_cast< ::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel >(_impl_.idempotency_level_);
}
inline ::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel MethodOptions::idempotency_level() const {
// @@protoc_insertion_point(field_get:google.protobuf.MethodOptions.idempotency_level)
return _internal_idempotency_level();
}
inline void MethodOptions::set_idempotency_level(::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel value) {
_internal_set_idempotency_level(value);
// @@protoc_insertion_point(field_set:google.protobuf.MethodOptions.idempotency_level)
}
inline ::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel MethodOptions::_internal_idempotency_level() const {
return static_cast<::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel>(_impl_.idempotency_level_);
}
inline void MethodOptions::_internal_set_idempotency_level(::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel value) {
assert(::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel_IsValid(value));
_impl_._has_bits_[0] |= 0x00000002u;
_impl_.idempotency_level_ = value;
}
inline void MethodOptions::set_idempotency_level(::PROTOBUF_NAMESPACE_ID::MethodOptions_IdempotencyLevel value) {
_internal_set_idempotency_level(value);
// @@protoc_insertion_point(field_set:google.protobuf.MethodOptions.idempotency_level)
}
// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999;
inline int MethodOptions::_internal_uninterpreted_option_size() const {
@ -14406,22 +14424,22 @@ inline void GeneratedCodeInfo_Annotation::clear_semantic() {
_impl_.semantic_ = 0;
_impl_._has_bits_[0] &= ~0x00000008u;
}
inline ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic GeneratedCodeInfo_Annotation::_internal_semantic() const {
return static_cast< ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic >(_impl_.semantic_);
}
inline ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic GeneratedCodeInfo_Annotation::semantic() const {
// @@protoc_insertion_point(field_get:google.protobuf.GeneratedCodeInfo.Annotation.semantic)
return _internal_semantic();
}
inline void GeneratedCodeInfo_Annotation::set_semantic(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic value) {
_internal_set_semantic(value);
// @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.semantic)
}
inline ::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic GeneratedCodeInfo_Annotation::_internal_semantic() const {
return static_cast<::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic>(_impl_.semantic_);
}
inline void GeneratedCodeInfo_Annotation::_internal_set_semantic(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic value) {
assert(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic_IsValid(value));
_impl_._has_bits_[0] |= 0x00000008u;
_impl_.semantic_ = value;
}
inline void GeneratedCodeInfo_Annotation::set_semantic(::PROTOBUF_NAMESPACE_ID::GeneratedCodeInfo_Annotation_Semantic value) {
_internal_set_semantic(value);
// @@protoc_insertion_point(field_set:google.protobuf.GeneratedCodeInfo.Annotation.semantic)
}
// -------------------------------------------------------------------

Loading…
Cancel
Save