diff options
author | Jisi Liu <jisi.liu@gmail.com> | 2017-07-18 15:38:30 -0700 |
---|---|---|
committer | Jisi Liu <jisi.liu@gmail.com> | 2017-07-18 15:38:30 -0700 |
commit | 09354db1434859a31a3c81abebcc4018d42f2715 (patch) | |
tree | b87c7cdc2255e6c8062ab92b4082665cd698d753 /src/google | |
parent | 9053033a5076f82cf18b823c31f352e95e5bfd8d (diff) |
Merge from Google internal for 3.4 release
Diffstat (limited to 'src/google')
168 files changed, 11724 insertions, 4944 deletions
diff --git a/src/google/protobuf/any.pb.cc b/src/google/protobuf/any.pb.cc index 6c80aaa2..a7a1258c 100644 --- a/src/google/protobuf/any.pb.cc +++ b/src/google/protobuf/any.pb.cc @@ -32,20 +32,20 @@ namespace { } // namespace PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField - const TableStruct::entries[] = { + const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField - const TableStruct::aux[] = { + const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ::google::protobuf::internal::AuxillaryParseTableField(), }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const - TableStruct::schema[] = { + TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { NULL, NULL, 0, -1, -1, false }, }; -const ::google::protobuf::uint32 TableStruct::offsets[] = { +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, _internal_metadata_), ~0u, // no _extensions_ @@ -54,8 +54,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, type_url_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Any, value_), }; - -static const ::google::protobuf::internal::MigrationSchema schemas[] = { +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { 0, -1, sizeof(Any)}, }; @@ -85,12 +84,6 @@ void protobuf_RegisterTypes(const ::std::string&) { } } // namespace - -void TableStruct::Shutdown() { - _Any_default_instance_.Shutdown(); - delete file_level_metadata[0].reflection; -} - void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -104,7 +97,7 @@ void InitDefaults() { } void AddDescriptorsImpl() { InitDefaults(); - static const char descriptor[] = { + static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { "\n\031google/protobuf/any.proto\022\017google.prot" "obuf\"&\n\003Any\022\020\n\010type_url\030\001 \001(\t\022\r\n\005value\030\002" " \001(\014Bo\n\023com.google.protobufB\010AnyProtoP\001Z" @@ -116,14 +109,13 @@ void AddDescriptorsImpl() { descriptor, 205); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/any.proto", &protobuf_RegisterTypes); - ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); } void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -219,8 +211,13 @@ Any* Any::New(::google::protobuf::Arena* arena) const { void Any::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Any) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); value_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _internal_metadata_.Clear(); } bool Any::MergePartialFromCodedStream( @@ -236,7 +233,7 @@ bool Any::MergePartialFromCodedStream( // string type_url = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_type_url())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -252,7 +249,7 @@ bool Any::MergePartialFromCodedStream( // bytes value = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadBytes( input, this->mutable_value())); } else { @@ -263,12 +260,11 @@ bool Any::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -304,6 +300,10 @@ void Any::SerializeWithCachedSizes( 2, this->value(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Any) } @@ -331,6 +331,10 @@ void Any::SerializeWithCachedSizes( 2, this->value(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Any) return target; } @@ -339,6 +343,11 @@ size_t Any::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Any) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // string type_url = 1; if (this->type_url().size() > 0) { total_size += 1 + @@ -415,9 +424,11 @@ void Any::Swap(Any* other) { InternalSwap(other); } void Any::InternalSwap(Any* other) { + using std::swap; type_url_.Swap(&other->type_url_); value_.Swap(&other->value_); - std::swap(_cached_size_, other->_cached_size_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Any::GetMetadata() const { diff --git a/src/google/protobuf/any.pb.h b/src/google/protobuf/any.pb.h index bc05fb35..211e003b 100644 --- a/src/google/protobuf/any.pb.h +++ b/src/google/protobuf/any.pb.h @@ -49,8 +49,9 @@ struct LIBPROTOBUF_EXPORT TableStruct { static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; static void InitDefaultsImpl(); - static void Shutdown(); }; void LIBPROTOBUF_EXPORT AddDescriptors(); void LIBPROTOBUF_EXPORT InitDefaults(); @@ -69,7 +70,6 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in CopyFrom(from); return *this; } - static const ::google::protobuf::Descriptor* descriptor(); static const Any& default_instance(); @@ -91,6 +91,9 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in } void Swap(Any* other); + friend void swap(Any& a, Any& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -176,6 +179,10 @@ class LIBPROTOBUF_EXPORT Any : public ::google::protobuf::Message /* @@protoc_in // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ // Any // string type_url = 1; @@ -284,6 +291,9 @@ inline void Any::set_allocated_value(::std::string* value) { // @@protoc_insertion_point(field_set_allocated:google.protobuf.Any.value) } +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // @@protoc_insertion_point(namespace_scope) diff --git a/src/google/protobuf/any.proto b/src/google/protobuf/any.proto index 9bd3f50a..c7486676 100644 --- a/src/google/protobuf/any.proto +++ b/src/google/protobuf/any.proto @@ -74,6 +74,16 @@ option objc_class_prefix = "GPB"; // any.Unpack(foo) // ... // +// Example 4: Pack and unpack a message in Go +// +// foo := &pb.Foo{...} +// any, err := ptypes.MarshalAny(foo) +// ... +// foo := &pb.Foo{} +// if err := ptypes.UnmarshalAny(any, foo); err != nil { +// ... +// } +// // The pack methods provided by protobuf library will by default use // 'type.googleapis.com/full.type.name' as the type URL and the unpack // methods only use the fully qualified type name after the last '/' diff --git a/src/google/protobuf/api.pb.cc b/src/google/protobuf/api.pb.cc index 94c6685f..0b36f430 100644 --- a/src/google/protobuf/api.pb.cc +++ b/src/google/protobuf/api.pb.cc @@ -36,22 +36,22 @@ namespace { } // namespace PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField - const TableStruct::entries[] = { + const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField - const TableStruct::aux[] = { + const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ::google::protobuf::internal::AuxillaryParseTableField(), }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const - TableStruct::schema[] = { + TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, }; -const ::google::protobuf::uint32 TableStruct::offsets[] = { +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Api, _internal_metadata_), ~0u, // no _extensions_ @@ -84,8 +84,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Mixin, root_), }; - -static const ::google::protobuf::internal::MigrationSchema schemas[] = { +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { 0, -1, sizeof(Api)}, { 12, -1, sizeof(Method)}, { 24, -1, sizeof(Mixin)}, @@ -119,16 +118,6 @@ void protobuf_RegisterTypes(const ::std::string&) { } } // namespace - -void TableStruct::Shutdown() { - _Api_default_instance_.Shutdown(); - delete file_level_metadata[0].reflection; - _Method_default_instance_.Shutdown(); - delete file_level_metadata[1].reflection; - _Mixin_default_instance_.Shutdown(); - delete file_level_metadata[2].reflection; -} - void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -148,7 +137,7 @@ void InitDefaults() { } void AddDescriptorsImpl() { InitDefaults(); - static const char descriptor[] = { + static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { "\n\031google/protobuf/api.proto\022\017google.prot" "obuf\032$google/protobuf/source_context.pro" "to\032\032google/protobuf/type.proto\"\201\002\n\003Api\022\014" @@ -175,14 +164,13 @@ void AddDescriptorsImpl() { "google/protobuf/api.proto", &protobuf_RegisterTypes); ::google::protobuf::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::AddDescriptors(); ::google::protobuf::protobuf_google_2fprotobuf_2ftype_2eproto::AddDescriptors(); - ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); } void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -253,9 +241,7 @@ Api::~Api() { void Api::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); version_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != internal_default_instance()) { - delete source_context_; - } + delete source_context_; } void Api::SetCachedSize(int size) const { @@ -283,6 +269,10 @@ Api* Api::New(::google::protobuf::Arena* arena) const { void Api::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Api) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + methods_.Clear(); options_.Clear(); mixins_.Clear(); @@ -293,6 +283,7 @@ void Api::Clear() { } source_context_ = NULL; syntax_ = 0; + _internal_metadata_.Clear(); } bool Api::MergePartialFromCodedStream( @@ -308,7 +299,7 @@ bool Api::MergePartialFromCodedStream( // string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -324,7 +315,7 @@ bool Api::MergePartialFromCodedStream( // repeated .google.protobuf.Method methods = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_methods())); } else { @@ -336,7 +327,7 @@ bool Api::MergePartialFromCodedStream( // repeated .google.protobuf.Option options = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_options())); } else { @@ -348,7 +339,7 @@ bool Api::MergePartialFromCodedStream( // string version = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(34u)) { + static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_version())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -364,7 +355,7 @@ bool Api::MergePartialFromCodedStream( // .google.protobuf.SourceContext source_context = 5; case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(42u)) { + static_cast< ::google::protobuf::uint8>(42u /* 42 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_source_context())); } else { @@ -376,7 +367,7 @@ bool Api::MergePartialFromCodedStream( // repeated .google.protobuf.Mixin mixins = 6; case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(50u)) { + static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_mixins())); } else { @@ -388,7 +379,7 @@ bool Api::MergePartialFromCodedStream( // .google.protobuf.Syntax syntax = 7; case 7: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(56u)) { + static_cast< ::google::protobuf::uint8>(56u /* 56 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -402,12 +393,11 @@ bool Api::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -477,6 +467,10 @@ void Api::SerializeWithCachedSizes( 7, this->syntax(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Api) } @@ -542,6 +536,10 @@ void Api::SerializeWithCachedSizes( 7, this->syntax(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Api) return target; } @@ -550,6 +548,11 @@ size_t Api::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Api) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // repeated .google.protobuf.Method methods = 2; { unsigned int count = this->methods_size(); @@ -681,14 +684,16 @@ void Api::Swap(Api* other) { InternalSwap(other); } void Api::InternalSwap(Api* other) { + using std::swap; methods_.InternalSwap(&other->methods_); options_.InternalSwap(&other->options_); mixins_.InternalSwap(&other->mixins_); name_.Swap(&other->name_); version_.Swap(&other->version_); - std::swap(source_context_, other->source_context_); - std::swap(syntax_, other->syntax_); - std::swap(_cached_size_, other->_cached_size_); + swap(source_context_, other->source_context_); + swap(syntax_, other->syntax_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Api::GetMetadata() const { @@ -874,9 +879,10 @@ void Api::clear_source_context() { source_context_ = NULL; } const ::google::protobuf::SourceContext& Api::source_context() const { + const ::google::protobuf::SourceContext* p = source_context_; // @@protoc_insertion_point(field_get:google.protobuf.Api.source_context) - return source_context_ != NULL ? *source_context_ - : *::google::protobuf::SourceContext::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceContext*>( + &::google::protobuf::_SourceContext_default_instance_); } ::google::protobuf::SourceContext* Api::mutable_source_context() { @@ -1039,12 +1045,17 @@ Method* Method::New(::google::protobuf::Arena* arena) const { void Method::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Method) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + options_.Clear(); name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); request_type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); response_type_url_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); ::memset(&request_streaming_, 0, reinterpret_cast<char*>(&syntax_) - reinterpret_cast<char*>(&request_streaming_) + sizeof(syntax_)); + _internal_metadata_.Clear(); } bool Method::MergePartialFromCodedStream( @@ -1060,7 +1071,7 @@ bool Method::MergePartialFromCodedStream( // string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1076,7 +1087,7 @@ bool Method::MergePartialFromCodedStream( // string request_type_url = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_request_type_url())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1092,7 +1103,7 @@ bool Method::MergePartialFromCodedStream( // bool request_streaming = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(24u)) { + static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -1106,7 +1117,7 @@ bool Method::MergePartialFromCodedStream( // string response_type_url = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(34u)) { + static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_response_type_url())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1122,7 +1133,7 @@ bool Method::MergePartialFromCodedStream( // bool response_streaming = 5; case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(40u)) { + static_cast< ::google::protobuf::uint8>(40u /* 40 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -1136,7 +1147,7 @@ bool Method::MergePartialFromCodedStream( // repeated .google.protobuf.Option options = 6; case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(50u)) { + static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_options())); } else { @@ -1148,7 +1159,7 @@ bool Method::MergePartialFromCodedStream( // .google.protobuf.Syntax syntax = 7; case 7: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(56u)) { + static_cast< ::google::protobuf::uint8>(56u /* 56 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -1162,12 +1173,11 @@ bool Method::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -1239,6 +1249,10 @@ void Method::SerializeWithCachedSizes( 7, this->syntax(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Method) } @@ -1304,6 +1318,10 @@ void Method::SerializeWithCachedSizes( 7, this->syntax(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Method) return target; } @@ -1312,6 +1330,11 @@ size_t Method::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Method) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // repeated .google.protobuf.Option options = 6; { unsigned int count = this->options_size(); @@ -1436,14 +1459,16 @@ void Method::Swap(Method* other) { InternalSwap(other); } void Method::InternalSwap(Method* other) { + using std::swap; options_.InternalSwap(&other->options_); name_.Swap(&other->name_); request_type_url_.Swap(&other->request_type_url_); response_type_url_.Swap(&other->response_type_url_); - std::swap(request_streaming_, other->request_streaming_); - std::swap(response_streaming_, other->response_streaming_); - std::swap(syntax_, other->syntax_); - std::swap(_cached_size_, other->_cached_size_); + swap(request_streaming_, other->request_streaming_); + swap(response_streaming_, other->response_streaming_); + swap(syntax_, other->syntax_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Method::GetMetadata() const { @@ -1759,8 +1784,13 @@ Mixin* Mixin::New(::google::protobuf::Arena* arena) const { void Mixin::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Mixin) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); root_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _internal_metadata_.Clear(); } bool Mixin::MergePartialFromCodedStream( @@ -1776,7 +1806,7 @@ bool Mixin::MergePartialFromCodedStream( // string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1792,7 +1822,7 @@ bool Mixin::MergePartialFromCodedStream( // string root = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_root())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1807,12 +1837,11 @@ bool Mixin::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -1852,6 +1881,10 @@ void Mixin::SerializeWithCachedSizes( 2, this->root(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Mixin) } @@ -1883,6 +1916,10 @@ void Mixin::SerializeWithCachedSizes( 2, this->root(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Mixin) return target; } @@ -1891,6 +1928,11 @@ size_t Mixin::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Mixin) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // string name = 1; if (this->name().size() > 0) { total_size += 1 + @@ -1967,9 +2009,11 @@ void Mixin::Swap(Mixin* other) { InternalSwap(other); } void Mixin::InternalSwap(Mixin* other) { + using std::swap; name_.Swap(&other->name_); root_.Swap(&other->root_); - std::swap(_cached_size_, other->_cached_size_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Mixin::GetMetadata() const { diff --git a/src/google/protobuf/api.pb.h b/src/google/protobuf/api.pb.h index 108c63a4..ad1f2f42 100644 --- a/src/google/protobuf/api.pb.h +++ b/src/google/protobuf/api.pb.h @@ -37,30 +37,12 @@ namespace protobuf { class Api; class ApiDefaultTypeInternal; LIBPROTOBUF_EXPORT extern ApiDefaultTypeInternal _Api_default_instance_; -class Enum; -class EnumDefaultTypeInternal; -LIBPROTOBUF_EXPORT extern EnumDefaultTypeInternal _Enum_default_instance_; -class EnumValue; -class EnumValueDefaultTypeInternal; -LIBPROTOBUF_EXPORT extern EnumValueDefaultTypeInternal _EnumValue_default_instance_; -class Field; -class FieldDefaultTypeInternal; -LIBPROTOBUF_EXPORT extern FieldDefaultTypeInternal _Field_default_instance_; class Method; class MethodDefaultTypeInternal; LIBPROTOBUF_EXPORT extern MethodDefaultTypeInternal _Method_default_instance_; class Mixin; class MixinDefaultTypeInternal; LIBPROTOBUF_EXPORT extern MixinDefaultTypeInternal _Mixin_default_instance_; -class Option; -class OptionDefaultTypeInternal; -LIBPROTOBUF_EXPORT extern OptionDefaultTypeInternal _Option_default_instance_; -class SourceContext; -class SourceContextDefaultTypeInternal; -LIBPROTOBUF_EXPORT extern SourceContextDefaultTypeInternal _SourceContext_default_instance_; -class Type; -class TypeDefaultTypeInternal; -LIBPROTOBUF_EXPORT extern TypeDefaultTypeInternal _Type_default_instance_; } // namespace protobuf } // namespace google @@ -74,8 +56,9 @@ struct LIBPROTOBUF_EXPORT TableStruct { static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; static void InitDefaultsImpl(); - static void Shutdown(); }; void LIBPROTOBUF_EXPORT AddDescriptors(); void LIBPROTOBUF_EXPORT InitDefaults(); @@ -94,7 +77,21 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in CopyFrom(from); return *this; } + #if LANG_CXX11 + Api(Api&& from) noexcept + : Api() { + *this = ::std::move(from); + } + inline Api& operator=(Api&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif static const ::google::protobuf::Descriptor* descriptor(); static const Api& default_instance(); @@ -106,6 +103,9 @@ class LIBPROTOBUF_EXPORT Api : public ::google::protobuf::Message /* @@protoc_in 0; void Swap(Api* other); + friend void swap(Api& a, Api& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -253,7 +253,21 @@ class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc CopyFrom(from); return *this; } + #if LANG_CXX11 + Method(Method&& from) noexcept + : Method() { + *this = ::std::move(from); + } + inline Method& operator=(Method&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif static const ::google::protobuf::Descriptor* descriptor(); static const Method& default_instance(); @@ -265,6 +279,9 @@ class LIBPROTOBUF_EXPORT Method : public ::google::protobuf::Message /* @@protoc 1; void Swap(Method* other); + friend void swap(Method& a, Method& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -405,7 +422,21 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_ CopyFrom(from); return *this; } + #if LANG_CXX11 + Mixin(Mixin&& from) noexcept + : Mixin() { + *this = ::std::move(from); + } + inline Mixin& operator=(Mixin&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif static const ::google::protobuf::Descriptor* descriptor(); static const Mixin& default_instance(); @@ -417,6 +448,9 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_ 2; void Swap(Mixin* other); + friend void swap(Mixin& a, Mixin& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -501,6 +535,10 @@ class LIBPROTOBUF_EXPORT Mixin : public ::google::protobuf::Message /* @@protoc_ // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ // Api // string name = 1; @@ -678,9 +716,10 @@ inline void Api::clear_source_context() { source_context_ = NULL; } inline const ::google::protobuf::SourceContext& Api::source_context() const { + const ::google::protobuf::SourceContext* p = source_context_; // @@protoc_insertion_point(field_get:google.protobuf.Api.source_context) - return source_context_ != NULL ? *source_context_ - : *::google::protobuf::SourceContext::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceContext*>( + &::google::protobuf::_SourceContext_default_instance_); } inline ::google::protobuf::SourceContext* Api::mutable_source_context() { @@ -1097,6 +1136,9 @@ inline void Mixin::set_allocated_root(::std::string* root) { // @@protoc_insertion_point(field_set_allocated:google.protobuf.Mixin.root) } +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // ------------------------------------------------------------------- diff --git a/src/google/protobuf/api.proto b/src/google/protobuf/api.proto index 7c30e8b7..f37ee2fa 100644 --- a/src/google/protobuf/api.proto +++ b/src/google/protobuf/api.proto @@ -42,26 +42,33 @@ option java_multiple_files = true; option objc_class_prefix = "GPB"; option go_package = "google.golang.org/genproto/protobuf/api;api"; -// Api is a light-weight descriptor for a protocol buffer service. +// Api is a light-weight descriptor for an API Interface. +// +// Interfaces are also described as "protocol buffer services" in some contexts, +// such as by the "service" keyword in a .proto file, but they are different +// from API Services, which represent a concrete implementation of an interface +// as opposed to simply a description of methods and bindings. They are also +// sometimes simply referred to as "APIs" in other contexts, such as the name of +// this message itself. See https://cloud.google.com/apis/design/glossary for +// detailed terminology. message Api { - // The fully qualified name of this api, including package name - // followed by the api's simple name. + // The fully qualified name of this interface, including package name + // followed by the interface's simple name. string name = 1; - // The methods of this api, in unspecified order. + // The methods of this interface, in unspecified order. repeated Method methods = 2; - // Any metadata attached to the API. + // Any metadata attached to the interface. repeated Option options = 3; - // A version string for this api. If specified, must have the form - // `major-version.minor-version`, as in `1.10`. If the minor version - // is omitted, it defaults to zero. If the entire version field is - // empty, the major version is derived from the package name, as - // outlined below. If the field is not empty, the version in the - // package name will be verified to be consistent with what is - // provided here. + // A version string for this interface. If specified, must have the form + // `major-version.minor-version`, as in `1.10`. If the minor version is + // omitted, it defaults to zero. If the entire version field is empty, the + // major version is derived from the package name, as outlined below. If the + // field is not empty, the version in the package name will be verified to be + // consistent with what is provided here. // // The versioning schema uses [semantic // versioning](http://semver.org) where the major version number @@ -71,10 +78,10 @@ message Api { // chosen based on the product plan. // // The major version is also reflected in the package name of the - // API, which must end in `v<major-version>`, as in + // interface, which must end in `v<major-version>`, as in // `google.feature.v1`. For major versions 0 and 1, the suffix can // be omitted. Zero major versions must only be used for - // experimental, none-GA apis. + // experimental, non-GA interfaces. // // string version = 4; @@ -83,14 +90,14 @@ message Api { // message. SourceContext source_context = 5; - // Included APIs. See [Mixin][]. + // Included interfaces. See [Mixin][]. repeated Mixin mixins = 6; // The source syntax of the service. Syntax syntax = 7; } -// Method represents a method of an api. +// Method represents a method of an API interface. message Method { // The simple name of this method. @@ -115,9 +122,9 @@ message Method { Syntax syntax = 7; } -// Declares an API to be included in this API. The including API must -// redeclare all the methods from the included API, but documentation -// and options are inherited as follows: +// Declares an API Interface to be included in this interface. The including +// interface must redeclare all the methods from the included interface, but +// documentation and options are inherited as follows: // // - If after comment and whitespace stripping, the documentation // string of the redeclared method is empty, it will be inherited @@ -129,7 +136,8 @@ message Method { // // - If an http annotation is inherited, the path pattern will be // modified as follows. Any version prefix will be replaced by the -// version of the including API plus the [root][] path if specified. +// version of the including interface plus the [root][] path if +// specified. // // Example of a simple mixin: // @@ -193,7 +201,7 @@ message Method { // ... // } message Mixin { - // The fully qualified name of the API which is included. + // The fully qualified name of the interface which is included. string name = 1; // If non-empty specifies a path under which inherited HTTP paths diff --git a/src/google/protobuf/arena.cc b/src/google/protobuf/arena.cc index 16cf8951..fe38f5dd 100755 --- a/src/google/protobuf/arena.cc +++ b/src/google/protobuf/arena.cc @@ -39,32 +39,35 @@ #endif // ADDRESS_SANITIZER namespace google { +static const size_t kMinCleanupListElements = 8; +static const size_t kMaxCleanupListElements = 64; // 1kB on 64-bit. + namespace protobuf { +namespace internal { -google::protobuf::internal::SequenceNumber Arena::lifecycle_id_generator_; +google::protobuf::internal::SequenceNumber ArenaImpl::lifecycle_id_generator_; #if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) -Arena::ThreadCache& Arena::thread_cache() { +ArenaImpl::ThreadCache& ArenaImpl::thread_cache() { static internal::ThreadLocalStorage<ThreadCache>* thread_cache_ = new internal::ThreadLocalStorage<ThreadCache>(); return *thread_cache_->Get(); } #elif defined(PROTOBUF_USE_DLLS) -Arena::ThreadCache& Arena::thread_cache() { +ArenaImpl::ThreadCache& ArenaImpl::thread_cache() { static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_ = { -1, NULL }; return thread_cache_; } #else -GOOGLE_THREAD_LOCAL Arena::ThreadCache Arena::thread_cache_ = { -1, NULL }; +GOOGLE_THREAD_LOCAL ArenaImpl::ThreadCache ArenaImpl::thread_cache_ = {-1, NULL}; #endif -void Arena::Init() { +void ArenaImpl::Init() { lifecycle_id_ = lifecycle_id_generator_.GetNext(); blocks_ = 0; hint_ = 0; space_allocated_ = 0; owns_first_block_ = true; - cleanup_list_ = 0; if (options_.initial_block != NULL && options_.initial_block_size > 0) { GOOGLE_CHECK_GE(options_.initial_block_size, sizeof(Block)) @@ -75,134 +78,154 @@ void Arena::Init() { first_block->size = options_.initial_block_size; first_block->pos = kHeaderSize; first_block->next = NULL; + first_block->cleanup = NULL; // Thread which calls Init() owns the first block. This allows the // single-threaded case to allocate on the first block without taking any // locks. first_block->owner = &thread_cache(); - SetThreadCacheBlock(first_block); AddBlockInternal(first_block); + CacheBlock(first_block); owns_first_block_ = false; } - - // Call the initialization hook - if (options_.on_arena_init != NULL) { - hooks_cookie_ = options_.on_arena_init(this); - } else { - hooks_cookie_ = NULL; - } } -Arena::~Arena() { - uint64 space_allocated = ResetInternal(); - - // Call the destruction hook - if (options_.on_arena_destruction != NULL) { - options_.on_arena_destruction(this, hooks_cookie_, space_allocated); - } -} +ArenaImpl::~ArenaImpl() { ResetInternal(); } -uint64 Arena::Reset() { +uint64 ArenaImpl::Reset() { // Invalidate any ThreadCaches pointing to any blocks we just destroyed. lifecycle_id_ = lifecycle_id_generator_.GetNext(); return ResetInternal(); } -uint64 Arena::ResetInternal() { - CleanupList(); - uint64 space_allocated = FreeBlocks(); - - // Call the reset hook - if (options_.on_arena_reset != NULL) { - options_.on_arena_reset(this, hooks_cookie_, space_allocated); - } +uint64 ArenaImpl::ResetInternal() { + Block* head = + reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_)); + CleanupList(head); + uint64 space_allocated = FreeBlocks(head); return space_allocated; } -Arena::Block* Arena::NewBlock(void* me, Block* my_last_block, size_t n, - size_t start_block_size, size_t max_block_size) { +ArenaImpl::Block* ArenaImpl::NewBlock(void* me, Block* my_last_block, + size_t min_bytes, size_t start_block_size, + size_t max_block_size) { size_t size; if (my_last_block != NULL) { // Double the current block size, up to a limit. - size = 2 * (my_last_block->size); - if (size > max_block_size) size = max_block_size; + size = std::min(2 * my_last_block->size, max_block_size); } else { size = start_block_size; } - // Verify that n + kHeaderSize won't overflow. - GOOGLE_CHECK_LE(n, std::numeric_limits<size_t>::max() - kHeaderSize); - size = std::max(size, kHeaderSize + n); + // Verify that min_bytes + kHeaderSize won't overflow. + GOOGLE_CHECK_LE(min_bytes, std::numeric_limits<size_t>::max() - kHeaderSize); + size = std::max(size, kHeaderSize + min_bytes); Block* b = reinterpret_cast<Block*>(options_.block_alloc(size)); - b->pos = kHeaderSize + n; + b->pos = kHeaderSize; b->size = size; b->owner = me; + b->cleanup = NULL; #ifdef ADDRESS_SANITIZER // Poison the rest of the block for ASAN. It was unpoisoned by the underlying // malloc but it's not yet usable until we return it as part of an allocation. ASAN_POISON_MEMORY_REGION( reinterpret_cast<char*>(b) + b->pos, b->size - b->pos); #endif // ADDRESS_SANITIZER + AddBlock(b); return b; } -void Arena::AddBlock(Block* b) { +void ArenaImpl::AddBlock(Block* b) { MutexLock l(&blocks_lock_); AddBlockInternal(b); } -void Arena::AddBlockInternal(Block* b) { +void ArenaImpl::AddBlockInternal(Block* b) { b->next = reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_)); google::protobuf::internal::Release_Store(&blocks_, reinterpret_cast<google::protobuf::internal::AtomicWord>(b)); - if (b->avail() != 0) { - // Direct future allocations to this block. - google::protobuf::internal::Release_Store(&hint_, reinterpret_cast<google::protobuf::internal::AtomicWord>(b)); - } space_allocated_ += b->size; } -void Arena::AddListNode(void* elem, void (*cleanup)(void*)) { - Node* node = reinterpret_cast<Node*>(AllocateAligned(sizeof(Node))); +ArenaImpl::Block* ArenaImpl::ExpandCleanupList(Block* b) { + size_t size = b->cleanup ? b->cleanup->size * 2 : kMinCleanupListElements; + size = std::min(size, kMaxCleanupListElements); + size_t bytes = internal::AlignUpTo8(CleanupChunk::SizeOf(size)); + if (b->avail() < bytes) { + b = GetBlock(bytes); + } + CleanupChunk* list = + reinterpret_cast<CleanupChunk*>(AllocFromBlock(b, bytes)); + list->next = b->cleanup; + list->size = size; + list->len = 0; + b->cleanup = list; + return b; +} + +inline GOOGLE_ATTRIBUTE_ALWAYS_INLINE void ArenaImpl::AddCleanupInBlock( + Block* b, void* elem, void (*cleanup)(void*)) { + if (b->cleanup == NULL || b->cleanup->len == b->cleanup->size) { + b = ExpandCleanupList(b); + } + + CleanupNode* node = &b->cleanup->nodes[b->cleanup->len++]; + node->elem = elem; node->cleanup = cleanup; - node->next = reinterpret_cast<Node*>( - google::protobuf::internal::NoBarrier_AtomicExchange(&cleanup_list_, - reinterpret_cast<google::protobuf::internal::AtomicWord>(node))); } -void* Arena::AllocateAligned(const std::type_info* allocated, size_t n) { - // Align n to next multiple of 8 (from Hacker's Delight, Chapter 3.) - n = (n + 7) & -8; +void ArenaImpl::AddCleanup(void* elem, void (*cleanup)(void*)) { + return AddCleanupInBlock(GetBlock(0), elem, cleanup); +} - // Monitor allocation if needed. - if (GOOGLE_PREDICT_FALSE(hooks_cookie_ != NULL) && - options_.on_arena_allocation != NULL) { - options_.on_arena_allocation(allocated, n, hooks_cookie_); - } +void* ArenaImpl::AllocateAligned(size_t n) { + GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned. + + return AllocFromBlock(GetBlock(n), n); +} + +void* ArenaImpl::AllocateAlignedAndAddCleanup(size_t n, + void (*cleanup)(void*)) { + GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned. + + Block* b = GetBlock(n); + void* mem = AllocFromBlock(b, n); + AddCleanupInBlock(b, mem, cleanup); + return mem; +} + +inline GOOGLE_ATTRIBUTE_ALWAYS_INLINE ArenaImpl::Block* ArenaImpl::GetBlock(size_t n) { + Block* my_block = NULL; // If this thread already owns a block in this arena then try to use that. // This fast path optimizes the case where multiple threads allocate from the // same arena. - if (thread_cache().last_lifecycle_id_seen == lifecycle_id_ && - thread_cache().last_block_used_ != NULL) { - if (thread_cache().last_block_used_->avail() < n) { - return SlowAlloc(n); + ThreadCache* tc = &thread_cache(); + if (tc->last_lifecycle_id_seen == lifecycle_id_) { + my_block = tc->last_block_used_; + if (my_block->avail() >= n) { + return my_block; } - return AllocFromBlock(thread_cache().last_block_used_, n); } // Check whether we own the last accessed block on this arena. // This fast path optimizes the case where a single thread uses multiple // arenas. - void* me = &thread_cache(); Block* b = reinterpret_cast<Block*>(google::protobuf::internal::Acquire_Load(&hint_)); - if (!b || b->owner != me || b->avail() < n) { - return SlowAlloc(n); + if (b != NULL && b->owner == tc) { + my_block = b; + if (my_block->avail() >= n) { + return my_block; + } } - return AllocFromBlock(b, n); + return GetBlockSlow(tc, my_block, n); } -void* Arena::AllocFromBlock(Block* b, size_t n) { +inline GOOGLE_ATTRIBUTE_ALWAYS_INLINE void* ArenaImpl::AllocFromBlock(Block* b, + size_t n) { + GOOGLE_DCHECK_EQ(internal::AlignUpTo8(b->pos), b->pos); // Must be already aligned. + GOOGLE_DCHECK_EQ(internal::AlignUpTo8(n), n); // Must be already aligned. + GOOGLE_DCHECK_GE(b->avail(), n); size_t p = b->pos; b->pos = p + n; #ifdef ADDRESS_SANITIZER @@ -211,27 +234,32 @@ void* Arena::AllocFromBlock(Block* b, size_t n) { return reinterpret_cast<char*>(b) + p; } -void* Arena::SlowAlloc(size_t n) { - void* me = &thread_cache(); +ArenaImpl::Block* ArenaImpl::GetBlockSlow(void* me, Block* my_full_block, + size_t n) { Block* b = FindBlock(me); // Find block owned by me. - // See if allocation fits in my latest block. - if (b != NULL && b->avail() >= n) { - SetThreadCacheBlock(b); - google::protobuf::internal::NoBarrier_Store(&hint_, reinterpret_cast<google::protobuf::internal::AtomicWord>(b)); - return AllocFromBlock(b, n); + if (b == NULL || b->avail() < n) { + b = NewBlock(me, b, n, options_.start_block_size, options_.max_block_size); + + // Try to steal the cleanup list from my_full_block. It's too full for this + // allocation, but it might have space left in its cleanup list and there's + // no reason to waste that memory. + if (my_full_block) { + GOOGLE_DCHECK_EQ(my_full_block->owner, me); + GOOGLE_DCHECK(b->cleanup == NULL); + b->cleanup = my_full_block->cleanup; + my_full_block->cleanup = NULL; + } } - b = NewBlock(me, b, n, options_.start_block_size, options_.max_block_size); - AddBlock(b); - SetThreadCacheBlock(b); - return reinterpret_cast<char*>(b) + kHeaderSize; + CacheBlock(b); + return b; } -uint64 Arena::SpaceAllocated() const { +uint64 ArenaImpl::SpaceAllocated() const { MutexLock l(&blocks_lock_); return space_allocated_; } -uint64 Arena::SpaceUsed() const { +uint64 ArenaImpl::SpaceUsed() const { uint64 space_used = 0; Block* b = reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_)); while (b != NULL) { @@ -241,14 +269,11 @@ uint64 Arena::SpaceUsed() const { return space_used; } -std::pair<uint64, uint64> Arena::SpaceAllocatedAndUsed() const { - return std::make_pair(SpaceAllocated(), SpaceUsed()); -} - -uint64 Arena::FreeBlocks() { +uint64 ArenaImpl::FreeBlocks(Block* head) { uint64 space_allocated = 0; - Block* b = reinterpret_cast<Block*>(google::protobuf::internal::NoBarrier_Load(&blocks_)); Block* first_block = NULL; + Block* b = head; + while (b != NULL) { space_allocated += (b->size); Block* next = b->next; @@ -281,27 +306,35 @@ uint64 Arena::FreeBlocks() { // Make the first block that was passed in through ArenaOptions // available for reuse. first_block->pos = kHeaderSize; + first_block->cleanup = NULL; // Thread which calls Reset() owns the first block. This allows the // single-threaded case to allocate on the first block without taking any // locks. first_block->owner = &thread_cache(); - SetThreadCacheBlock(first_block); AddBlockInternal(first_block); + CacheBlock(first_block); } return space_allocated; } -void Arena::CleanupList() { - Node* head = - reinterpret_cast<Node*>(google::protobuf::internal::NoBarrier_Load(&cleanup_list_)); - while (head != NULL) { - head->cleanup(head->elem); - head = head->next; +void ArenaImpl::CleanupList(Block* head) { + // Have to do this in a first pass, because some of the destructors might + // refer to memory in other blocks. + for (Block* b = head; b; b = b->next) { + CleanupChunk* list = b->cleanup; + while (list) { + size_t n = list->len; + CleanupNode* node = &list->nodes[list->len - 1]; + for (size_t i = 0; i < n; i++, node--) { + node->cleanup(node->elem); + } + list = list->next; + } + b->cleanup = NULL; } - cleanup_list_ = 0; } -Arena::Block* Arena::FindBlock(void* me) { +ArenaImpl::Block* ArenaImpl::FindBlock(void* me) { // TODO(sanjay): We might want to keep a separate list with one // entry per thread. Block* b = reinterpret_cast<Block*>(google::protobuf::internal::Acquire_Load(&blocks_)); @@ -311,5 +344,14 @@ Arena::Block* Arena::FindBlock(void* me) { return b; } +} // namespace internal + +void Arena::OnArenaAllocation(const std::type_info* allocated_type, + size_t n) const { + if (on_arena_allocation_ != NULL) { + on_arena_allocation_(allocated_type, n, hooks_cookie_); + } +} + } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/arena.h b/src/google/protobuf/arena.h index b6a375ac..1497a6c5 100644 --- a/src/google/protobuf/arena.h +++ b/src/google/protobuf/arena.h @@ -37,7 +37,7 @@ #ifdef max #undef max // Visual Studio defines this macro #endif -#if __cplusplus >= 201103L +#if LANG_CXX11 #include <google/protobuf/stubs/type_traits.h> #endif #if defined(_MSC_VER) && !_HAS_EXCEPTIONS @@ -51,13 +51,7 @@ using type_info = ::type_info; #include <typeinfo> #endif -#include <google/protobuf/stubs/atomic_sequence_num.h> -#include <google/protobuf/stubs/atomicops.h> -#include <google/protobuf/stubs/common.h> -#include <google/protobuf/stubs/logging.h> -#include <google/protobuf/stubs/mutex.h> -#include <google/protobuf/stubs/type_traits.h> - +#include <google/protobuf/arena_impl.h> namespace google { namespace protobuf { @@ -122,7 +116,6 @@ struct ArenaOptions { // from the arena. By default, it contains a ptr to a wrapper function that // calls free. void (*block_dealloc)(void*, size_t); - // Hooks for adding external functionality such as user-specific metrics // collection, specific debugging abilities, etc. // Init hook may return a pointer to a cookie to be stored in the arena. @@ -225,21 +218,38 @@ class LIBPROTOBUF_EXPORT Arena { public: // Arena constructor taking custom options. See ArenaOptions below for // descriptions of the options available. - explicit Arena(const ArenaOptions& options) : options_(options) { - Init(); + explicit Arena(const ArenaOptions& options) : impl_(options) { + Init(options); } // Default constructor with sensible default options, tuned for average // use-cases. - Arena() { - Init(); + Arena() : impl_(ArenaOptions()) { Init(ArenaOptions()); } + + ~Arena() { + uint64 space_allocated = SpaceAllocated(); + // Call the reset hook + if (on_arena_reset_ != NULL) { + on_arena_reset_(this, hooks_cookie_, space_allocated); + } + + // Call the destruction hook + if (on_arena_destruction_ != NULL) { + on_arena_destruction_(this, hooks_cookie_, space_allocated); + } } - // Destructor deletes all owned heap allocated objects, and destructs objects - // that have non-trivial destructors, except for proto2 message objects whose - // destructors can be skipped. Also, frees all blocks except the initial block - // if it was passed in. - ~Arena(); + void Init(const ArenaOptions& options) { + on_arena_allocation_ = options.on_arena_allocation; + on_arena_reset_ = options.on_arena_reset; + on_arena_destruction_ = options.on_arena_destruction; + // Call the initialization hook + if (options.on_arena_init != NULL) { + hooks_cookie_ = options.on_arena_init(this); + } else { + hooks_cookie_ = NULL; + } + } // API to create proto2 message objects on the arena. If the arena passed in // is NULL, then a heap allocated object is returned. Type T must be a message @@ -253,10 +263,15 @@ class LIBPROTOBUF_EXPORT Arena { // allocation protocol, documented above. template <typename T> GOOGLE_ATTRIBUTE_ALWAYS_INLINE static T* CreateMessage(::google::protobuf::Arena* arena) { +#if LANG_CXX11 + static_assert( + InternalHelper<T>::is_arena_constructable::value, + "CreateMessage can only construct types that are ArenaConstructable"); +#endif if (arena == NULL) { return new T; } else { - return arena->CreateMessageInternal<T>(static_cast<T*>(0)); + return arena->CreateMessageInternal<T>(); } } @@ -265,11 +280,15 @@ class LIBPROTOBUF_EXPORT Arena { // take additional constructor arguments. template <typename T, typename Arg> GOOGLE_ATTRIBUTE_ALWAYS_INLINE static T* CreateMessage(::google::protobuf::Arena* arena, const Arg& arg) { +#if LANG_CXX11 + static_assert( + InternalHelper<T>::is_arena_constructable::value, + "CreateMessage can only construct types that are ArenaConstructable"); +#endif if (arena == NULL) { return new T(NULL, arg); } else { - return arena->CreateMessageInternal<T>(static_cast<T*>(0), - arg); + return arena->CreateMessageInternal<T>(arg); } } @@ -280,11 +299,15 @@ class LIBPROTOBUF_EXPORT Arena { static T* CreateMessage(::google::protobuf::Arena* arena, const Arg1& arg1, const Arg2& arg2) { +#if LANG_CXX11 + static_assert( + InternalHelper<T>::is_arena_constructable::value, + "CreateMessage can only construct types that are ArenaConstructable"); +#endif if (arena == NULL) { return new T(NULL, arg1, arg2); } else { - return arena->CreateMessageInternal<T>(static_cast<T*>(0), - arg1, arg2); + return arena->CreateMessageInternal<T>(arg1, arg2); } } @@ -463,24 +486,33 @@ class LIBPROTOBUF_EXPORT Arena { // Returns the total space allocated by the arena, which is the sum of the // sizes of the underlying blocks. This method is relatively fast; a counter // is kept as blocks are allocated. - uint64 SpaceAllocated() const; + uint64 SpaceAllocated() const { return impl_.SpaceAllocated(); } // Returns the total space used by the arena. Similar to SpaceAllocated but // does not include free space and block overhead. The total space returned // may not include space used by other threads executing concurrently with // the call to this method. - GOOGLE_ATTRIBUTE_NOINLINE uint64 SpaceUsed() const; + uint64 SpaceUsed() const { return impl_.SpaceUsed(); } // DEPRECATED. Please use SpaceAllocated() and SpaceUsed(). // // Combines SpaceAllocated and SpaceUsed. Returns a pair of // <space_allocated, space_used>. - GOOGLE_ATTRIBUTE_NOINLINE std::pair<uint64, uint64> SpaceAllocatedAndUsed() const; + std::pair<uint64, uint64> SpaceAllocatedAndUsed() const { + return std::make_pair(SpaceAllocated(), SpaceUsed()); + } // Frees all storage allocated by this arena after calling destructors // registered with OwnDestructor() and freeing objects registered with Own(). // Any objects allocated on this arena are unusable after this call. It also // returns the total space used by the arena which is the sums of the sizes // of the allocated blocks. This method is not thread-safe. - GOOGLE_ATTRIBUTE_NOINLINE uint64 Reset(); + GOOGLE_ATTRIBUTE_NOINLINE uint64 Reset() { + uint64 space_allocated = SpaceAllocated(); + // Call the reset hook + if (on_arena_reset_ != NULL) { + on_arena_reset_(this, hooks_cookie_, space_allocated); + } + return impl_.Reset(); + } // Adds |object| to a list of heap-allocated objects to be freed with |delete| // when the arena is destroyed or reset. @@ -497,7 +529,7 @@ class LIBPROTOBUF_EXPORT Arena { template <typename T> GOOGLE_ATTRIBUTE_NOINLINE void OwnDestructor(T* object) { if (object != NULL) { - AddListNode(object, &internal::arena_destruct_object<T>); + impl_.AddCleanup(object, &internal::arena_destruct_object<T>); } } @@ -507,7 +539,7 @@ class LIBPROTOBUF_EXPORT Arena { // the class destructor. GOOGLE_ATTRIBUTE_NOINLINE void OwnCustomDestructor(void* object, void (*destruct)(void*)) { - AddListNode(object, destruct); + impl_.AddCleanup(object, destruct); } // Retrieves the arena associated with |value| if |value| is an arena-capable @@ -516,19 +548,59 @@ class LIBPROTOBUF_EXPORT Arena { // resolves at compile-time. template<typename T> GOOGLE_ATTRIBUTE_ALWAYS_INLINE static ::google::protobuf::Arena* GetArena(const T* value) { - return GetArenaInternal(value, static_cast<T*>(0)); + return GetArenaInternal(value, is_arena_constructable<T>()); } - private: - struct InternalIsArenaConstructableHelper { + template <typename T> + class InternalHelper { + template <typename U> + static char DestructorSkippable(const typename U::DestructorSkippable_*); + template <typename U> + static double DestructorSkippable(...); + + typedef google::protobuf::internal::integral_constant< + bool, sizeof(DestructorSkippable<T>(static_cast<const T*>(0))) == + sizeof(char) || + google::protobuf::internal::has_trivial_destructor<T>::value> + is_destructor_skippable; + template<typename U> static char ArenaConstructable( const typename U::InternalArenaConstructable_*); template<typename U> static double ArenaConstructable(...); + + typedef google::protobuf::internal::integral_constant<bool, sizeof(ArenaConstructable<T>( + static_cast<const T*>(0))) == + sizeof(char)> + is_arena_constructable; + +#if LANG_CXX11 + template <typename... Args> + static T* Construct(void* ptr, Args&&... args) { + return new (ptr) T(std::forward<Args>(args)...); + } +#else + template <typename Arg1> + static T* Construct(void* ptr, const Arg1& arg1) { + return new (ptr) T(arg1); + } + template <typename Arg1, typename Arg2> + static T* Construct(void* ptr, const Arg1& arg1, const Arg2& arg2) { + return new (ptr) T(arg1, arg2); + } + template <typename Arg1, typename Arg2, typename Arg3> + static T* Construct(void* ptr, const Arg1& arg1, + const Arg2& arg2, const Arg3& arg3) { + return new (ptr) T(arg1, arg2, arg3); + } +#endif // LANG_CXX11 + + static Arena* GetArena(const T* p) { return p->GetArenaNoVirtual(); } + + friend class Arena; }; - public: // Helper typetrait that indicates support for arenas in a type T at compile // time. This is public only to allow construction of higher-level templated // utilities. is_arena_constructable<T>::value is true if the message type T @@ -537,113 +609,54 @@ class LIBPROTOBUF_EXPORT Arena { // This is inside Arena because only Arena has the friend relationships // necessary to see the underlying generated code traits. template <typename T> - struct is_arena_constructable - : public google::protobuf::internal::integral_constant< - bool, sizeof(InternalIsArenaConstructableHelper::ArenaConstructable< - const T>(static_cast<const T*>(0))) == sizeof(char)> { - }; + struct is_arena_constructable : InternalHelper<T>::is_arena_constructable {}; private: - // Blocks are variable length malloc-ed objects. The following structure - // describes the common header for all blocks. - struct Block { - void* owner; // &ThreadCache of thread that owns this block, or - // &this->owner if not yet owned by a thread. - Block* next; // Next block in arena (may have different owner) - // ((char*) &block) + pos is next available byte. It is always - // aligned at a multiple of 8 bytes. - size_t pos; - size_t size; // total size of the block. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE size_t avail() const { return size - pos; } - // data follows - }; - - template<typename Type> friend class ::google::protobuf::internal::GenericTypeHandler; - friend class MockArena; // For unit-testing. - friend class internal::ArenaString; // For AllocateAligned. - friend class internal::LazyField; // For CreateMaybeMessage. - - struct ThreadCache { - // The ThreadCache is considered valid as long as this matches the - // lifecycle_id of the arena being used. - int64 last_lifecycle_id_seen; - Block* last_block_used_; - }; - - static const size_t kHeaderSize = sizeof(Block); - static google::protobuf::internal::SequenceNumber lifecycle_id_generator_; -#if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) - // Android ndk does not support GOOGLE_THREAD_LOCAL keyword so we use a custom thread - // local storage class we implemented. - // iOS also does not support the GOOGLE_THREAD_LOCAL keyword. - static ThreadCache& thread_cache(); -#elif defined(PROTOBUF_USE_DLLS) - // Thread local variables cannot be exposed through DLL interface but we can - // wrap them in static functions. - static ThreadCache& thread_cache(); -#else - static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_; - static ThreadCache& thread_cache() { return thread_cache_; } -#endif - - // SFINAE for skipping addition to delete list for a message type when created - // with CreateMessage. This is mainly to skip proto2/proto1 message objects - // with cc_enable_arenas=true from being part of the delete list. Also, note, - // compiler will optimize out the branch in CreateInternal<T>. - template<typename T> - static inline bool SkipDeleteList(typename T::DestructorSkippable_*) { - return true; + void OnArenaAllocation(const std::type_info* allocated_type, size_t n) const; + inline void AllocHook(const std::type_info* allocated_type, size_t n) const { + if (GOOGLE_PREDICT_FALSE(hooks_cookie_ != NULL)) { + OnArenaAllocation(allocated_type, n); + } } - // For message objects that don't have the DestructorSkippable_ trait, we - // always add to the delete list. - template<typename T> - static inline bool SkipDeleteList(...) { - return google::protobuf::internal::has_trivial_destructor<T>::value; + // Allocate and also optionally call on_arena_allocation callback with the + // allocated type info when the hooks are in place in ArenaOptions and + // the cookie is not null. + template<typename T> GOOGLE_ATTRIBUTE_ALWAYS_INLINE + void* AllocateInternal(bool skip_explicit_ownership) { + const size_t n = internal::AlignUpTo8(sizeof(T)); + AllocHook(RTTI_TYPE_ID(T), n); + // Monitor allocation if needed. + if (skip_explicit_ownership) { + return impl_.AllocateAligned(n); + } else { + return impl_.AllocateAlignedAndAddCleanup( + n, &internal::arena_destruct_object<T>); + } } - private: - struct InternalIsDestructorSkippableHelper { - template<typename U> - static char DestructorSkippable( - const typename U::DestructorSkippable_*); - template<typename U> - static double DestructorSkippable(...); - }; - - public: - // Helper typetrait that indicates whether the desctructor of type T should be - // called when arena is destroyed at compile time. This is only to allow - // construction of higher-level templated utilities. - // is_destructor_skippable<T>::value is true if the destructor of the message - // type T should not be called when arena is destroyed or false otherwise. - // This is inside Arena because only Arena has the friend relationships - // necessary to see the underlying generated code traits. - template<typename T> - struct is_destructor_skippable - : public google::protobuf::internal::integral_constant< - bool, - sizeof(InternalIsDestructorSkippableHelper::DestructorSkippable< - const T>(static_cast<const T*>(0))) == sizeof(char) || - google::protobuf::internal::has_trivial_destructor<T>::value> {}; - - private: // CreateMessage<T> requires that T supports arenas, but this private method // works whether or not T supports arenas. These are not exposed to user code // as it can cause confusing API usages, and end up having double free in // user code. These are used only internally from LazyField and Repeated // fields, since they are designed to work in all mode combinations. - template<typename Msg> GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static Msg* CreateMaybeMessage( - Arena* arena, typename Msg::InternalArenaConstructable_*) { + template <typename Msg> + GOOGLE_ATTRIBUTE_ALWAYS_INLINE static Msg* CreateMaybeMessage(Arena* arena, + google::protobuf::internal::true_type) { return CreateMessage<Msg>(arena); } - template<typename T> GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static T* CreateMaybeMessage(Arena* arena, ...) { + template <typename T> + GOOGLE_ATTRIBUTE_ALWAYS_INLINE static T* CreateMaybeMessage(Arena* arena, + google::protobuf::internal::false_type) { return Create<T>(arena); } + template <typename T> + GOOGLE_ATTRIBUTE_ALWAYS_INLINE static T* CreateMaybeMessage(Arena* arena) { + return CreateMaybeMessage<T>(arena, is_arena_constructable<T>()); + } + // Just allocate the required size for the given type assuming the // type has a trivial constructor. template<typename T> GOOGLE_ATTRIBUTE_ALWAYS_INLINE @@ -651,47 +664,34 @@ class LIBPROTOBUF_EXPORT Arena { GOOGLE_CHECK_LE(num_elements, std::numeric_limits<size_t>::max() / sizeof(T)) << "Requested size is too large to fit into size_t."; - return static_cast<T*>( - AllocateAligned(RTTI_TYPE_ID(T), sizeof(T) * num_elements)); + const size_t n = internal::AlignUpTo8(sizeof(T) * num_elements); + // Monitor allocation if needed. + AllocHook(RTTI_TYPE_ID(T), n); + return static_cast<T*>(impl_.AllocateAligned(n)); } #if LANG_CXX11 template <typename T, typename... Args> GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateInternal(bool skip_explicit_ownership, Args&&... args) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) + return new (AllocateInternal<T>(skip_explicit_ownership)) T(std::forward<Args>(args)...); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object<T>); - } - return t; } -#endif +#else template <typename T> GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateInternal(bool skip_explicit_ownership) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T(); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object<T>); - } - return t; + return new (AllocateInternal<T>(skip_explicit_ownership)) T(); } template <typename T, typename Arg> GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateInternal(bool skip_explicit_ownership, const Arg& arg) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T(arg); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object<T>); - } - return t; + return new (AllocateInternal<T>(skip_explicit_ownership)) T(arg); } - template <typename T, typename Arg1, typename Arg2> GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateInternal( - bool skip_explicit_ownership, const Arg1& arg1, const Arg2& arg2) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) T(arg1, arg2); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object<T>); - } - return t; + template <typename T, typename Arg1, typename Arg2> + GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateInternal(bool skip_explicit_ownership, + const Arg1& arg1, + const Arg2& arg2) { + return new (AllocateInternal<T>(skip_explicit_ownership)) T(arg1, arg2); } template <typename T, typename Arg1, typename Arg2, typename Arg3> @@ -699,12 +699,8 @@ class LIBPROTOBUF_EXPORT Arena { const Arg1& arg1, const Arg2& arg2, const Arg3& arg3) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) + return new (AllocateInternal<T>(skip_explicit_ownership)) T(arg1, arg2, arg3); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object<T>); - } - return t; } template <typename T, typename Arg1, typename Arg2, typename Arg3, @@ -714,12 +710,8 @@ class LIBPROTOBUF_EXPORT Arena { const Arg2& arg2, const Arg3& arg3, const Arg4& arg4) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) + return new (AllocateInternal<T>(skip_explicit_ownership)) T(arg1, arg2, arg3, arg4); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object<T>); - } - return t; } template <typename T, typename Arg1, typename Arg2, typename Arg3, @@ -730,12 +722,8 @@ class LIBPROTOBUF_EXPORT Arena { const Arg3& arg3, const Arg4& arg4, const Arg5& arg5) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) + return new (AllocateInternal<T>(skip_explicit_ownership)) T(arg1, arg2, arg3, arg4, arg5); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object<T>); - } - return t; } template <typename T, typename Arg1, typename Arg2, typename Arg3, @@ -747,12 +735,8 @@ class LIBPROTOBUF_EXPORT Arena { const Arg4& arg4, const Arg5& arg5, const Arg6& arg6) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) + return new (AllocateInternal<T>(skip_explicit_ownership)) T(arg1, arg2, arg3, arg4, arg5, arg6); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object<T>); - } - return t; } template <typename T, typename Arg1, typename Arg2, typename Arg3, @@ -765,12 +749,8 @@ class LIBPROTOBUF_EXPORT Arena { const Arg5& arg5, const Arg6& arg6, const Arg7& arg7) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) + return new (AllocateInternal<T>(skip_explicit_ownership)) T(arg1, arg2, arg3, arg4, arg5, arg6, arg7); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object<T>); - } - return t; } template <typename T, typename Arg1, typename Arg2, typename Arg3, @@ -785,30 +765,30 @@ class LIBPROTOBUF_EXPORT Arena { const Arg6& arg6, const Arg7& arg7, const Arg8& arg8) { - T* t = new (AllocateAligned(RTTI_TYPE_ID(T), sizeof(T))) + return new (AllocateInternal<T>(skip_explicit_ownership)) T(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8); - if (!skip_explicit_ownership) { - AddListNode(t, &internal::arena_destruct_object<T>); - } - return t; } - - template <typename T> GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateMessageInternal(typename T::InternalArenaConstructable_*) { - return CreateInternal<T>(SkipDeleteList<T>(static_cast<T*>(0)), this); +#endif + template <typename T> + GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateMessageInternal() { + return InternalHelper<T>::Construct( + AllocateInternal<T>(InternalHelper<T>::is_destructor_skippable::value), + this); } - template <typename T, typename Arg> GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateMessageInternal(typename T::InternalArenaConstructable_*, - const Arg& arg) { - return CreateInternal<T>(SkipDeleteList<T>(static_cast<T*>(0)), this, arg); + template <typename T, typename Arg> + GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateMessageInternal(const Arg& arg) { + return InternalHelper<T>::Construct( + AllocateInternal<T>(InternalHelper<T>::is_destructor_skippable::value), + this, arg); } - template <typename T, typename Arg1, typename Arg2> GOOGLE_ATTRIBUTE_ALWAYS_INLINE - T* CreateMessageInternal(typename T::InternalArenaConstructable_*, - const Arg1& arg1, const Arg2& arg2) { - return CreateInternal<T>(SkipDeleteList<T>(static_cast<T*>(0)), this, arg1, - arg2); + template <typename T, typename Arg1, typename Arg2> + GOOGLE_ATTRIBUTE_ALWAYS_INLINE T* CreateMessageInternal(const Arg1& arg1, + const Arg2& arg2) { + return InternalHelper<T>::Construct( + AllocateInternal<T>(InternalHelper<T>::is_destructor_skippable::value), + this, arg1, arg2); } // CreateInArenaStorage is used to implement map field. Without it, @@ -818,14 +798,15 @@ class LIBPROTOBUF_EXPORT Arena { static void CreateInArenaStorage(T* ptr, Arena* arena) { CreateInArenaStorageInternal(ptr, arena, typename is_arena_constructable<T>::type()); - RegisterDestructorInternal(ptr, arena, - typename is_destructor_skippable<T>::type()); + RegisterDestructorInternal( + ptr, arena, + typename InternalHelper<T>::is_destructor_skippable::type()); } template <typename T> static void CreateInArenaStorageInternal( T* ptr, Arena* arena, google::protobuf::internal::true_type) { - new (ptr) T(arena); + InternalHelper<T>::Construct(ptr, arena); } template <typename T> static void CreateInArenaStorageInternal( @@ -850,100 +831,56 @@ class LIBPROTOBUF_EXPORT Arena { template<typename T> GOOGLE_ATTRIBUTE_ALWAYS_INLINE void OwnInternal(T* object, google::protobuf::internal::true_type) { if (object != NULL) { - AddListNode(object, &internal::arena_delete_object< ::google::protobuf::Message >); + impl_.AddCleanup(object, + &internal::arena_delete_object< ::google::protobuf::Message>); } } template<typename T> GOOGLE_ATTRIBUTE_ALWAYS_INLINE void OwnInternal(T* object, google::protobuf::internal::false_type) { if (object != NULL) { - AddListNode(object, &internal::arena_delete_object<T>); + impl_.AddCleanup(object, &internal::arena_delete_object<T>); } } // Implementation for GetArena(). Only message objects with // InternalArenaConstructable_ tags can be associated with an arena, and such // objects must implement a GetArenaNoVirtual() method. - template<typename T> GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static ::google::protobuf::Arena* GetArenaInternal( - const T* value, typename T::InternalArenaConstructable_*) { - return value->GetArenaNoVirtual(); + template <typename T> + GOOGLE_ATTRIBUTE_ALWAYS_INLINE static ::google::protobuf::Arena* GetArenaInternal( + const T* value, google::protobuf::internal::true_type) { + return InternalHelper<T>::GetArena(value); } - template<typename T> GOOGLE_ATTRIBUTE_ALWAYS_INLINE - static ::google::protobuf::Arena* GetArenaInternal(const T* value, ...) { + template <typename T> + GOOGLE_ATTRIBUTE_ALWAYS_INLINE static ::google::protobuf::Arena* GetArenaInternal( + const T* value, google::protobuf::internal::false_type) { return NULL; } - // Allocate and also optionally call on_arena_allocation callback with the - // allocated type info when the hooks are in place in ArenaOptions and - // the cookie is not null. - void* AllocateAligned(const std::type_info* allocated, size_t n); - - // Allocate an internal allocation, avoiding optional typed monitoring. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE void* AllocateAligned(size_t n) { - return AllocateAligned(NULL, n); - } - - void Init(); - - // Free all blocks and return the total space used which is the sums of sizes - // of the all the allocated blocks. - uint64 FreeBlocks(); - - // Add object pointer and cleanup function pointer to the list. - // TODO(rohananil, cfallin): We could pass in a sub-arena into this method - // to avoid polluting blocks of this arena with list nodes. This would help in - // mixed mode (where many protobufs have cc_enable_arenas=false), and is an - // alternative to a chunked linked-list, but with extra overhead of *next. - void AddListNode(void* elem, void (*cleanup)(void*)); - // Delete or Destruct all objects owned by the arena. - void CleanupList(); - uint64 ResetInternal(); - - inline void SetThreadCacheBlock(Block* block) { - thread_cache().last_block_used_ = block; - thread_cache().last_lifecycle_id_seen = lifecycle_id_; + // For friends of arena. + void* AllocateAligned(size_t n) { + AllocHook(NULL, n); + return impl_.AllocateAligned(internal::AlignUpTo8(n)); } - int64 lifecycle_id_; // Unique for each arena. Changes on Reset(). - - google::protobuf::internal::AtomicWord blocks_; // Head of linked list of all allocated blocks - google::protobuf::internal::AtomicWord hint_; // Fast thread-local block access - uint64 space_allocated_; // Sum of sizes of all allocated blocks. - - // Node contains the ptr of the object to be cleaned up and the associated - // cleanup function ptr. - struct Node { - void* elem; // Pointer to the object to be cleaned up. - void (*cleanup)(void*); // Function pointer to the destructor or deleter. - Node* next; // Next node in the list. - }; + internal::ArenaImpl impl_; - google::protobuf::internal::AtomicWord cleanup_list_; // Head of a linked list of nodes containing object - // ptrs and cleanup methods. - - bool owns_first_block_; // Indicates that arena owns the first block - mutable Mutex blocks_lock_; - - void AddBlock(Block* b); - // Access must be synchronized, either by blocks_lock_ or by being called from - // Init()/Reset(). - void AddBlockInternal(Block* b); - void* SlowAlloc(size_t n); - Block* FindBlock(void* me); - Block* NewBlock(void* me, Block* my_last_block, size_t n, - size_t start_block_size, size_t max_block_size); - static void* AllocFromBlock(Block* b, size_t n); - template <typename Key, typename T> - friend class Map; + void* (*on_arena_init_)(Arena* arena); + void (*on_arena_allocation_)(const std::type_info* allocated_type, + uint64 alloc_size, void* cookie); + void (*on_arena_reset_)(Arena* arena, void* cookie, uint64 space_used); + void (*on_arena_destruction_)(Arena* arena, void* cookie, uint64 space_used); // The arena may save a cookie it receives from the external on_init hook // and then use it when calling the on_reset and on_destruction hooks. void* hooks_cookie_; - ArenaOptions options_; - - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Arena); + template <typename Type> + friend class ::google::protobuf::internal::GenericTypeHandler; + friend class internal::ArenaString; // For AllocateAligned. + friend class internal::LazyField; // For CreateMaybeMessage. + template <typename Key, typename T> + friend class Map; }; // Defined above for supporting environments without RTTI. diff --git a/src/google/protobuf/arena_impl.h b/src/google/protobuf/arena_impl.h new file mode 100644 index 00000000..b7f0c7b6 --- /dev/null +++ b/src/google/protobuf/arena_impl.h @@ -0,0 +1,214 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// This file defines an Arena allocator for better allocation performance. + +#ifndef GOOGLE_PROTOBUF_ARENA_IMPL_H__ +#define GOOGLE_PROTOBUF_ARENA_IMPL_H__ + +#include <limits> + +#include <google/protobuf/stubs/atomic_sequence_num.h> +#include <google/protobuf/stubs/atomicops.h> +#include <google/protobuf/stubs/common.h> +#include <google/protobuf/stubs/logging.h> +#include <google/protobuf/stubs/mutex.h> +#include <google/protobuf/stubs/type_traits.h> + +namespace google { + +namespace protobuf { +namespace internal { + +inline size_t AlignUpTo8(size_t n) { + // Align n to next multiple of 8 (from Hacker's Delight, Chapter 3.) + return (n + 7) & -8; +} + +// This class provides the core Arena memory allocation library. Different +// implementations only need to implement the public interface below. +// Arena is not a template type as that would only be useful if all protos +// in turn would be templates, which will/cannot happen. However separating +// the memory allocation part from the cruft of the API users expect we can +// use #ifdef the select the best implementation based on hardware / OS. +class LIBPROTOBUF_EXPORT ArenaImpl { + public: + struct Options { + size_t start_block_size; + size_t max_block_size; + char* initial_block; + size_t initial_block_size; + void* (*block_alloc)(size_t); + void (*block_dealloc)(void*, size_t); + + template <typename O> + explicit Options(const O& options) + : start_block_size(options.start_block_size), + max_block_size(options.max_block_size), + initial_block(options.initial_block), + initial_block_size(options.initial_block_size), + block_alloc(options.block_alloc), + block_dealloc(options.block_dealloc) {} + }; + + template <typename O> + explicit ArenaImpl(const O& options) : options_(options) { + Init(); + } + + // Destructor deletes all owned heap allocated objects, and destructs objects + // that have non-trivial destructors, except for proto2 message objects whose + // destructors can be skipped. Also, frees all blocks except the initial block + // if it was passed in. + ~ArenaImpl(); + + uint64 Reset(); + + uint64 SpaceAllocated() const; + uint64 SpaceUsed() const; + + void* AllocateAligned(size_t n); + + void* AllocateAlignedAndAddCleanup(size_t n, void (*cleanup)(void*)); + + // Add object pointer and cleanup function pointer to the list. + void AddCleanup(void* elem, void (*cleanup)(void*)); + + private: + // Node contains the ptr of the object to be cleaned up and the associated + // cleanup function ptr. + struct CleanupNode { + void* elem; // Pointer to the object to be cleaned up. + void (*cleanup)(void*); // Function pointer to the destructor or deleter. + }; + + // Cleanup uses a chunked linked list, to reduce pointer chasing. + struct CleanupChunk { + static size_t SizeOf(size_t i) { + return sizeof(CleanupChunk) + (sizeof(CleanupNode) * (i - 1)); + } + size_t len; // Number of elements currently present. + size_t size; // Total elements in the list. + CleanupChunk* next; // Next node in the list. + CleanupNode nodes[1]; // True length is |size|. + }; + + // Blocks are variable length malloc-ed objects. The following structure + // describes the common header for all blocks. + struct Block { + void* owner; // &ThreadCache of thread that owns this block. + Block* next; // Next block in arena (may have different owner) + CleanupChunk* cleanup; // Head of cleanup list (may point to another block, + // but it must have the same owner). + // ((char*) &block) + pos is next available byte. It is always + // aligned at a multiple of 8 bytes. + size_t pos; + size_t size; // total size of the block. + GOOGLE_ATTRIBUTE_ALWAYS_INLINE size_t avail() const { return size - pos; } + // data follows + }; + + struct ThreadCache { + // The ThreadCache is considered valid as long as this matches the + // lifecycle_id of the arena being used. + int64 last_lifecycle_id_seen; + Block* last_block_used_; + }; + + // kHeaderSize is sizeof(Block), aligned up to the nearest multiple of 8 to + // protect the invariant that pos is always at a multiple of 8. + static const size_t kHeaderSize = (sizeof(Block) + 7) & -8; +#if LANG_CXX11 + static_assert(kHeaderSize % 8 == 0, "kHeaderSize must be a multiple of 8."); +#endif + static google::protobuf::internal::SequenceNumber lifecycle_id_generator_; +#if defined(GOOGLE_PROTOBUF_NO_THREADLOCAL) + // Android ndk does not support GOOGLE_THREAD_LOCAL keyword so we use a custom thread + // local storage class we implemented. + // iOS also does not support the GOOGLE_THREAD_LOCAL keyword. + static ThreadCache& thread_cache(); +#elif defined(PROTOBUF_USE_DLLS) + // Thread local variables cannot be exposed through DLL interface but we can + // wrap them in static functions. + static ThreadCache& thread_cache(); +#else + static GOOGLE_THREAD_LOCAL ThreadCache thread_cache_; + static ThreadCache& thread_cache() { return thread_cache_; } +#endif + + void Init(); + + // Free all blocks and return the total space used which is the sums of sizes + // of the all the allocated blocks. + uint64 FreeBlocks(Block* head); + + void AddCleanupInBlock(Block* b, void* elem, void (*cleanup)(void*)); + Block* ExpandCleanupList(Block* b); + // Delete or Destruct all objects owned by the arena. + void CleanupList(Block* head); + uint64 ResetInternal(); + + inline void CacheBlock(Block* block) { + thread_cache().last_block_used_ = block; + thread_cache().last_lifecycle_id_seen = lifecycle_id_; + google::protobuf::internal::Release_Store(&hint_, reinterpret_cast<google::protobuf::internal::AtomicWord>(block)); + } + + google::protobuf::internal::AtomicWord blocks_; // Head of linked list of all allocated blocks + google::protobuf::internal::AtomicWord hint_; // Fast thread-local block access + uint64 space_allocated_; // Sum of sizes of all allocated blocks. + + bool owns_first_block_; // Indicates that arena owns the first block + mutable Mutex blocks_lock_; + + void AddBlock(Block* b); + // Access must be synchronized, either by blocks_lock_ or by being called from + // Init()/Reset(). + void AddBlockInternal(Block* b); + // Returns a block owned by this thread. + Block* GetBlock(size_t n); + Block* GetBlockSlow(void* me, Block* my_full_block, size_t n); + Block* FindBlock(void* me); + Block* NewBlock(void* me, Block* my_last_block, size_t min_bytes, + size_t start_block_size, size_t max_block_size); + static void* AllocFromBlock(Block* b, size_t n); + + int64 lifecycle_id_; // Unique for each arena. Changes on Reset(). + + Options options_; + + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ArenaImpl); +}; + +} // namespace internal +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_ARENA_IMPL_H__ diff --git a/src/google/protobuf/arenastring_unittest.cc b/src/google/protobuf/arenastring_unittest.cc index e5afe42d..c330b903 100644 --- a/src/google/protobuf/arenastring_unittest.cc +++ b/src/google/protobuf/arenastring_unittest.cc @@ -32,16 +32,21 @@ #include <google/protobuf/arenastring.h> -#include <string> +#include <algorithm> +#include <cstdlib> #include <memory> #ifndef _SHARED_PTR_H #include <google/protobuf/stubs/shared_ptr.h> #endif -#include <cstdlib> +#include <string> +#include <vector> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <gtest/gtest.h> +#include <google/protobuf/io/coded_stream.h> +#include <google/protobuf/io/zero_copy_stream_impl.h> + namespace google { using google::protobuf::internal::ArenaString; @@ -87,7 +92,8 @@ TEST(ArenaStringPtrTest, ArenaStringPtrOnArena) { EXPECT_EQ(string("default"), field.Get()); field.Set(&default_value, WrapString("Test short"), &arena); EXPECT_EQ(string("Test short"), field.Get()); - field.Set(&default_value, WrapString("Test long long long long value"), &arena); + field.Set(&default_value, WrapString("Test long long long long value"), + &arena); EXPECT_EQ(string("Test long long long long value"), field.Get()); field.Set(&default_value, string(""), &arena); field.Destroy(&default_value, &arena); @@ -104,5 +110,6 @@ TEST(ArenaStringPtrTest, ArenaStringPtrOnArena) { field2.Destroy(&default_value, &arena); } + } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/compiler/code_generator.h b/src/google/protobuf/compiler/code_generator.h index b917d373..8b9f42e2 100644 --- a/src/google/protobuf/compiler/code_generator.h +++ b/src/google/protobuf/compiler/code_generator.h @@ -50,6 +50,7 @@ namespace io { class ZeroCopyOutputStream; } class FileDescriptor; namespace compiler { +class AccessInfoMap; class Version; // Defined in this file. @@ -112,7 +113,8 @@ class LIBPROTOC_EXPORT CodeGenerator { // runs. class LIBPROTOC_EXPORT GeneratorContext { public: - inline GeneratorContext() {} + inline GeneratorContext() { + } virtual ~GeneratorContext(); // Opens the given file, truncating it if it exists, and returns a @@ -148,6 +150,7 @@ class LIBPROTOC_EXPORT GeneratorContext { // this GeneratorContext. virtual void GetCompilerVersion(Version* version) const; + private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(GeneratorContext); }; @@ -162,8 +165,8 @@ typedef GeneratorContext OutputDirectory; // "foo=bar,baz,qux=corge" // parses to the pairs: // ("foo", "bar"), ("baz", ""), ("qux", "corge") -extern void ParseGeneratorParameter(const string&, - std::vector<std::pair<string, string> >*); +LIBPROTOC_EXPORT void ParseGeneratorParameter(const string&, + std::vector<std::pair<string, string> >*); } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/command_line_interface.cc b/src/google/protobuf/compiler/command_line_interface.cc index 7fcd0083..afe63a77 100644 --- a/src/google/protobuf/compiler/command_line_interface.cc +++ b/src/google/protobuf/compiler/command_line_interface.cc @@ -33,6 +33,8 @@ // Sanjay Ghemawat, Jeff Dean, and others. #include <google/protobuf/compiler/command_line_interface.h> + + #include <google/protobuf/stubs/platform_macros.h> #include <stdio.h> @@ -68,19 +70,19 @@ #endif #include <google/protobuf/stubs/common.h> +#include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/stringprintf.h> -#include <google/protobuf/compiler/importer.h> -#include <google/protobuf/compiler/code_generator.h> -#include <google/protobuf/compiler/plugin.pb.h> #include <google/protobuf/compiler/subprocess.h> #include <google/protobuf/compiler/zip_writer.h> -#include <google/protobuf/descriptor.h> -#include <google/protobuf/text_format.h> -#include <google/protobuf/dynamic_message.h> +#include <google/protobuf/compiler/plugin.pb.h> +#include <google/protobuf/compiler/code_generator.h> +#include <google/protobuf/compiler/importer.h> #include <google/protobuf/io/coded_stream.h> -#include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/io/printer.h> -#include <google/protobuf/stubs/logging.h> +#include <google/protobuf/io/zero_copy_stream_impl.h> +#include <google/protobuf/descriptor.h> +#include <google/protobuf/dynamic_message.h> +#include <google/protobuf/text_format.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> #include <google/protobuf/stubs/map_util.h> @@ -116,11 +118,6 @@ namespace compiler { #endif namespace { -#if defined(_WIN32) && !defined(__CYGWIN__) -static const char* kPathSeparator = ";"; -#else -static const char* kPathSeparator = ":"; -#endif static const char* kDefaultDirectDependenciesViolationMsg = "File is imported but not declared in --direct_dependencies: %s"; @@ -278,11 +275,14 @@ string PluginName(const string& plugin_prefix, const string& directive) { // strip the "--" and "_out/_opt" and add the plugin prefix. return plugin_prefix + "gen-" + directive.substr(2, directive.size() - 6); } + } // namespace // A MultiFileErrorCollector that prints errors to stderr. -class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector, - public io::ErrorCollector { +class CommandLineInterface::ErrorPrinter + : public MultiFileErrorCollector, + public io::ErrorCollector, + public DescriptorPool::ErrorCollector { public: ErrorPrinter(ErrorFormat format, DiskSourceTree *tree = NULL) : format_(format), tree_(tree), found_errors_(false) {} @@ -309,6 +309,25 @@ class CommandLineInterface::ErrorPrinter : public MultiFileErrorCollector, AddErrorOrWarning("input", line, column, message, "warning", std::clog); } + // implements DescriptorPool::ErrorCollector------------------------- + void AddError( + const string& filename, + const string& element_name, + const Message* descriptor, + ErrorLocation location, + const string& message) { + AddErrorOrWarning(filename, -1, -1, message, "error", std::cerr); + } + + void AddWarning( + const string& filename, + const string& element_name, + const Message* descriptor, + ErrorLocation location, + const string& message) { + AddErrorOrWarning(filename, -1, -1, message, "warning", std::clog); + } + bool FoundErrors() const { return found_errors_; } private: @@ -410,6 +429,13 @@ class CommandLineInterface::MemoryOutputStream virtual int64 ByteCount() const { return inner_->ByteCount(); } private: + // Checks to see if "filename_.meta" exists in directory_; if so, fixes the + // offsets in that GeneratedCodeInfo record to reflect bytes inserted in + // filename_ at original offset insertion_offset with length insertion_length. + // We assume that insertions will not occur within any given annotated span + // of text. + void UpdateMetadata(size_t insertion_offset, size_t insertion_length); + // Where to insert the string when it's done. GeneratorContextImpl* directory_; string filename_; @@ -430,8 +456,7 @@ class CommandLineInterface::MemoryOutputStream CommandLineInterface::GeneratorContextImpl::GeneratorContextImpl( const std::vector<const FileDescriptor*>& parsed_files) : parsed_files_(parsed_files), - had_error_(false) { -} + had_error_(false) {} CommandLineInterface::GeneratorContextImpl::~GeneratorContextImpl() { STLDeleteValues(&files_); @@ -607,6 +632,44 @@ CommandLineInterface::MemoryOutputStream::MemoryOutputStream( inner_(new io::StringOutputStream(&data_)) { } +void CommandLineInterface::MemoryOutputStream::UpdateMetadata( + size_t insertion_offset, size_t insertion_length) { + std::map<string, string*>::iterator meta_file = + directory_->files_.find(filename_ + ".meta"); + if (meta_file == directory_->files_.end() || !meta_file->second) { + // No metadata was recorded for this file. + return; + } + string* encoded_data = meta_file->second; + GeneratedCodeInfo metadata; + bool is_text_format = false; + if (!metadata.ParseFromString(*encoded_data)) { + if (!TextFormat::ParseFromString(*encoded_data, &metadata)) { + // The metadata is invalid. + std::cerr << filename_ + << ".meta: Could not parse metadata as wire or text format." + << std::endl; + return; + } + // Generators that use the public plugin interface emit text-format + // metadata (because in the public plugin protocol, file content must be + // UTF8-encoded strings). + is_text_format = true; + } + for (int i = 0; i < metadata.annotation_size(); ++i) { + GeneratedCodeInfo::Annotation* annotation = metadata.mutable_annotation(i); + if (annotation->begin() >= insertion_offset) { + annotation->set_begin(annotation->begin() + insertion_length); + annotation->set_end(annotation->end() + insertion_length); + } + } + if (is_text_format) { + TextFormat::PrintToString(metadata, encoded_data); + } else { + metadata.SerializeToString(encoded_data); + } +} + CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() { // Make sure all data has been written. inner_.reset(); @@ -684,6 +747,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() { if (indent_.empty()) { // No indent. This makes things easier. target->insert(pos, data_); + UpdateMetadata(pos, data_.size()); } else { // Calculate how much space we need. int indent_size = 0; @@ -693,6 +757,7 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() { // Make a hole for it. target->insert(pos, data_.size() + indent_size, '\0'); + UpdateMetadata(pos, data_.size() + indent_size); // Now copy in the data. string::size_type data_pos = 0; @@ -720,6 +785,12 @@ CommandLineInterface::MemoryOutputStream::~MemoryOutputStream() { // =================================================================== +#if defined(_WIN32) && !defined(__CYGWIN__) +const char* const CommandLineInterface::kPathSeparator = ";"; +#else +const char* const CommandLineInterface::kPathSeparator = ":"; +#endif + CommandLineInterface::CommandLineInterface() : mode_(MODE_COMPILE), print_mode_(PRINT_NONE), @@ -729,9 +800,7 @@ CommandLineInterface::CommandLineInterface() kDefaultDirectDependenciesViolationMsg), imports_in_descriptor_set_(false), source_info_in_descriptor_set_(false), - disallow_services_(false), - inputs_are_proto_path_relative_(false) { -} + disallow_services_(false) {} CommandLineInterface::~CommandLineInterface() {} void CommandLineInterface::RegisterGenerator(const string& flag_name, @@ -772,61 +841,39 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { break; } - AddDefaultProtoPaths(&proto_path_); - - // Set up the source tree. - DiskSourceTree source_tree; - for (int i = 0; i < proto_path_.size(); i++) { - source_tree.MapPath(proto_path_[i].first, proto_path_[i].second); - } - - // Map input files to virtual paths if necessary. - if (!inputs_are_proto_path_relative_) { - if (!MakeInputsBeProtoPathRelative(&source_tree)) { + std::vector<const FileDescriptor*> parsed_files; + // null unless descriptor_set_in_names_.empty() + google::protobuf::scoped_ptr<DiskSourceTree> disk_source_tree; + google::protobuf::scoped_ptr<ErrorPrinter> error_collector; + google::protobuf::scoped_ptr<DescriptorPool> descriptor_pool; + google::protobuf::scoped_ptr<DescriptorDatabase> descriptor_database; + if (descriptor_set_in_names_.empty()) { + disk_source_tree.reset(new DiskSourceTree()); + if (!InitializeDiskSourceTree(disk_source_tree.get())) { return 1; } - } - - // Allocate the Importer. - ErrorPrinter error_collector(error_format_, &source_tree); - Importer importer(&source_tree, &error_collector); - - std::vector<const FileDescriptor*> parsed_files; + error_collector.reset( + new ErrorPrinter(error_format_, disk_source_tree.get())); - // Parse each file. - for (int i = 0; i < input_files_.size(); i++) { - // Import the file. - importer.AddUnusedImportTrackFile(input_files_[i]); - const FileDescriptor* parsed_file = importer.Import(input_files_[i]); - importer.ClearUnusedImportTrackFiles(); - if (parsed_file == NULL) return 1; - parsed_files.push_back(parsed_file); + SourceTreeDescriptorDatabase* database = + new SourceTreeDescriptorDatabase(disk_source_tree.get()); + database->RecordErrorsTo(error_collector.get()); + descriptor_database.reset(database); + descriptor_pool.reset(new DescriptorPool( + descriptor_database.get(), database->GetValidationErrorCollector())); + } else { + error_collector.reset(new ErrorPrinter(error_format_)); - // Enforce --disallow_services. - if (disallow_services_ && parsed_file->service_count() > 0) { - std::cerr << parsed_file->name() << ": This file contains services, but " - "--disallow_services was used." << std::endl; + SimpleDescriptorDatabase* database = new SimpleDescriptorDatabase(); + descriptor_database.reset(database); + if (!PopulateSimpleDescriptorDatabase(database)) { return 1; } - - // Enforce --direct_dependencies - if (direct_dependencies_explicitly_set_) { - bool indirect_imports = false; - for (int i = 0; i < parsed_file->dependency_count(); i++) { - if (direct_dependencies_.find(parsed_file->dependency(i)->name()) == - direct_dependencies_.end()) { - indirect_imports = true; - std::cerr << parsed_file->name() << ": " - << StringReplace(direct_dependencies_violation_msg_, "%s", - parsed_file->dependency(i)->name(), - true /* replace_all */) - << std::endl; - } - } - if (indirect_imports) { - return 1; - } - } + descriptor_pool.reset(new DescriptorPool(database, error_collector.get())); + } + descriptor_pool->EnforceWeakDependencies(true); + if (!ParseInputFiles(descriptor_pool.get(), &parsed_files)) { + return 1; } // We construct a separate GeneratorContext for each output location. Note @@ -879,15 +926,16 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { } if (!dependency_out_name_.empty()) { + GOOGLE_DCHECK(disk_source_tree.get()); if (!GenerateDependencyManifestFile(parsed_files, output_directories, - &source_tree)) { + disk_source_tree.get())) { return 1; } } STLDeleteValues(&output_directories); - if (!descriptor_set_name_.empty()) { + if (!descriptor_set_out_name_.empty()) { if (!WriteDescriptorSet(parsed_files)) { return 1; } @@ -906,13 +954,13 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { return 1; } } else { - if (!EncodeOrDecode(importer.pool())) { + if (!EncodeOrDecode(descriptor_pool.get())) { return 1; } } } - if (error_collector.FoundErrors()) { + if (error_collector->FoundErrors()) { return 1; } @@ -928,7 +976,7 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { break; case PRINT_NONE: GOOGLE_LOG(ERROR) << "If the code reaches here, it usually means a bug of " - "flag parsing in the CommonadLineInterface."; + "flag parsing in the CommandLineInterface."; return 1; // Do not add a default case. @@ -938,6 +986,112 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) { return 0; } +bool CommandLineInterface::InitializeDiskSourceTree( + DiskSourceTree* source_tree) { + AddDefaultProtoPaths(&proto_path_); + + // Set up the source tree. + for (int i = 0; i < proto_path_.size(); i++) { + source_tree->MapPath(proto_path_[i].first, proto_path_[i].second); + } + + // Map input files to virtual paths if possible. + if (!MakeInputsBeProtoPathRelative(source_tree)) { + return false; + } + return true; +} + +bool CommandLineInterface::PopulateSimpleDescriptorDatabase( + SimpleDescriptorDatabase* database) { + for (int i = 0; i < descriptor_set_in_names_.size(); i++) { + int fd; + do { + fd = open(descriptor_set_in_names_[i].c_str(), O_RDONLY | O_BINARY); + } while (fd < 0 && errno == EINTR); + if (fd < 0) { + std::cerr << descriptor_set_in_names_[i] << ": " + << strerror(ENOENT) << std::endl; + return false; + } + + FileDescriptorSet file_descriptor_set; + bool parsed = file_descriptor_set.ParseFromFileDescriptor(fd); + if (close(fd) != 0) { + std::cerr << descriptor_set_in_names_[i] << ": close: " + << strerror(errno); + return false; + } + + if (!parsed) { + std::cerr << descriptor_set_in_names_[i] << ": Unable to parse." + << std::endl; + return false; + } + + for (int j = 0; j < file_descriptor_set.file_size(); j++) { + FileDescriptorProto previously_added_file_descriptor_proto; + if (database->FindFileByName(file_descriptor_set.file(j).name(), + &previously_added_file_descriptor_proto)) { + // already present - skip + continue; + } + if (!database->Add(file_descriptor_set.file(j))) { + return false; + } + } + } + return true; +} + +bool CommandLineInterface::ParseInputFiles( + DescriptorPool* descriptor_pool, + std::vector<const FileDescriptor*>* parsed_files) { + + // Parse each file. + for (int i = 0; i < input_files_.size(); i++) { + // Import the file. + descriptor_pool->AddUnusedImportTrackFile(input_files_[i]); + const FileDescriptor* parsed_file = + descriptor_pool->FindFileByName(input_files_[i]); + descriptor_pool->ClearUnusedImportTrackFiles(); + if (parsed_file == NULL) { + if (!descriptor_set_in_names_.empty()) { + std::cerr << input_files_[i] << ": " << strerror(ENOENT) << std::endl; + } + return false; + } + parsed_files->push_back(parsed_file); + + // Enforce --disallow_services. + if (disallow_services_ && parsed_file->service_count() > 0) { + std::cerr << parsed_file->name() << ": This file contains services, but " + "--disallow_services was used." << std::endl; + return false; + } + + // Enforce --direct_dependencies + if (direct_dependencies_explicitly_set_) { + bool indirect_imports = false; + for (int i = 0; i < parsed_file->dependency_count(); i++) { + if (direct_dependencies_.find(parsed_file->dependency(i)->name()) == + direct_dependencies_.end()) { + indirect_imports = true; + std::cerr << parsed_file->name() << ": " + << StringReplace(direct_dependencies_violation_msg_, "%s", + parsed_file->dependency(i)->name(), + true /* replace_all */) + << std::endl; + } + } + if (indirect_imports) { + return false; + } + } + } + return true; +} + void CommandLineInterface::Clear() { // Clear all members that are set by Run(). Note that we must not clear // members which are set by other methods before Run() is called. @@ -948,7 +1102,8 @@ void CommandLineInterface::Clear() { direct_dependencies_violation_msg_ = kDefaultDirectDependenciesViolationMsg; output_directives_.clear(); codec_type_.clear(); - descriptor_set_name_.clear(); + descriptor_set_in_names_.clear(); + descriptor_set_out_name_.clear(); dependency_out_name_.clear(); mode_ = MODE_COMPILE; @@ -962,6 +1117,17 @@ void CommandLineInterface::Clear() { bool CommandLineInterface::MakeInputsBeProtoPathRelative( DiskSourceTree* source_tree) { for (int i = 0; i < input_files_.size(); i++) { + // If the input file path is not a physical file path, it must be a virtual + // path. + if (access(input_files_[i].c_str(), F_OK) < 0) { + string disk_file; + if (source_tree->VirtualFileToDiskFile(input_files_[i], &disk_file)) { + return true; + } else { + std::cerr << input_files_[i] << ": " << strerror(ENOENT) << std::endl; + return false; + } + } string virtual_file, shadowing_disk_file; switch (source_tree->DiskFileToVirtualFile( input_files_[i], &virtual_file, &shadowing_disk_file)) { @@ -979,12 +1145,14 @@ bool CommandLineInterface::MakeInputsBeProtoPathRelative( case DiskSourceTree::CANNOT_OPEN: std::cerr << input_files_[i] << ": " << strerror(errno) << std::endl; return false; - case DiskSourceTree::NO_MAPPING: - // First check if the file exists at all. - if (access(input_files_[i].c_str(), F_OK) < 0) { - // File does not even exist. - std::cerr << input_files_[i] << ": " << strerror(ENOENT) << std::endl; + case DiskSourceTree::NO_MAPPING: { + // Try to interpret the path as a virtual path. + string disk_file; + if (source_tree->VirtualFileToDiskFile(input_files_[i], &disk_file)) { + return true; } else { + // The input file path can't be mapped to any --proto_path and it also + // can't be interpreted as a virtual path. std::cerr << input_files_[i] << ": File does not reside within any path " @@ -993,9 +1161,11 @@ bool CommandLineInterface::MakeInputsBeProtoPathRelative( "proto_path must be an exact prefix of the .proto file " "names -- protoc is too dumb to figure out when two paths " "(e.g. absolute and relative) are equivalent (it's harder " - "than you think)." << std::endl; + "than you think)." + << std::endl; + return false; } - return false; + } } } @@ -1085,7 +1255,7 @@ CommandLineInterface::ParseArguments(int argc, const char* const argv[]) { return PARSE_ARGUMENT_FAIL; } if (mode_ == MODE_COMPILE && output_directives_.empty() && - descriptor_set_name_.empty()) { + descriptor_set_out_name_.empty()) { std::cerr << "Missing output directives." << std::endl; return PARSE_ARGUMENT_FAIL; } @@ -1100,11 +1270,11 @@ CommandLineInterface::ParseArguments(int argc, const char* const argv[]) { << std::endl; return PARSE_ARGUMENT_FAIL; } - if (imports_in_descriptor_set_ && descriptor_set_name_.empty()) { + if (imports_in_descriptor_set_ && descriptor_set_out_name_.empty()) { std::cerr << "--include_imports only makes sense when combined with " "--descriptor_set_out." << std::endl; } - if (source_info_in_descriptor_set_ && descriptor_set_name_.empty()) { + if (source_info_in_descriptor_set_ && descriptor_set_out_name_.empty()) { std::cerr << "--include_source_info only makes sense when combined with " "--descriptor_set_out." << std::endl; } @@ -1191,11 +1361,20 @@ CommandLineInterface::InterpretArgument(const string& name, input_files_.push_back(value); } else if (name == "-I" || name == "--proto_path") { + if (!descriptor_set_in_names_.empty()) { + std::cerr << "Only one of " << name + << " and --descriptor_set_in can be specified." + << std::endl; + return PARSE_ARGUMENT_FAIL; + } + // Java's -classpath (and some other languages) delimits path components // with colons. Let's accept that syntax too just to make things more // intuitive. std::vector<string> parts = Split( - value, kPathSeparator, true); + value, + CommandLineInterface::kPathSeparator, + true); for (int i = 0; i < parts.size(); i++) { string virtual_path; @@ -1253,8 +1432,38 @@ CommandLineInterface::InterpretArgument(const string& name, } else if (name == "--direct_dependencies_violation_msg") { direct_dependencies_violation_msg_ = value; + } else if (name == "--descriptor_set_in") { + if (!descriptor_set_in_names_.empty()) { + std::cerr << name << " may only be passed once. To specify multiple " + "descriptor sets, pass them all as a single " + "parameter separated by '" + << CommandLineInterface::kPathSeparator << "'." + << std::endl; + return PARSE_ARGUMENT_FAIL; + } + if (value.empty()) { + std::cerr << name << " requires a non-empty value." << std::endl; + return PARSE_ARGUMENT_FAIL; + } + if (!proto_path_.empty()) { + std::cerr << "Only one of " << name + << " and --proto_path can be specified." + << std::endl; + return PARSE_ARGUMENT_FAIL; + } + if (!dependency_out_name_.empty()) { + std::cerr << name << " cannot be used with --dependency_out." + << std::endl; + return PARSE_ARGUMENT_FAIL; + } + + descriptor_set_in_names_ = Split( + value, + CommandLineInterface::kPathSeparator, + true); + } else if (name == "-o" || name == "--descriptor_set_out") { - if (!descriptor_set_name_.empty()) { + if (!descriptor_set_out_name_.empty()) { std::cerr << name << " may only be passed once." << std::endl; return PARSE_ARGUMENT_FAIL; } @@ -1268,7 +1477,7 @@ CommandLineInterface::InterpretArgument(const string& name, "same time." << std::endl; return PARSE_ARGUMENT_FAIL; } - descriptor_set_name_ = value; + descriptor_set_out_name_ = value; } else if (name == "--dependency_out") { if (!dependency_out_name_.empty()) { @@ -1279,6 +1488,11 @@ CommandLineInterface::InterpretArgument(const string& name, std::cerr << name << " requires a non-empty value." << std::endl; return PARSE_ARGUMENT_FAIL; } + if (!descriptor_set_in_names_.empty()) { + std::cerr << name << " cannot be used with --descriptor_set_in." + << std::endl; + return PARSE_ARGUMENT_FAIL; + } dependency_out_name_ = value; } else if (name == "--include_imports") { @@ -1318,7 +1532,7 @@ CommandLineInterface::InterpretArgument(const string& name, << std::endl; return PARSE_ARGUMENT_FAIL; } - if (!output_directives_.empty() || !descriptor_set_name_.empty()) { + if (!output_directives_.empty() || !descriptor_set_out_name_.empty()) { std::cerr << "Cannot use " << name << " and generate code or descriptors at the same time." << std::endl; @@ -1384,7 +1598,7 @@ CommandLineInterface::InterpretArgument(const string& name, << "other info at the same time." << std::endl; return PARSE_ARGUMENT_FAIL; } - if (!output_directives_.empty() || !descriptor_set_name_.empty()) { + if (!output_directives_.empty() || !descriptor_set_out_name_.empty()) { std::cerr << "Cannot use " << name << " and generate code or descriptors at the same time." << std::endl; @@ -1476,6 +1690,14 @@ void CommandLineInterface::PrintHelpText() { " pairs in text format to standard output. No\n" " PROTO_FILES should be given when using this\n" " flag.\n" +" --descriptor_set_in=FILES Specifies a delimited list of FILES\n" +" each containing a FileDescriptorSet (a\n" +" protocol buffer defined in descriptor.proto).\n" +" The FileDescriptor for each of the PROTO_FILES\n" +" provided will be loaded from these\n" +" FileDescriptorSets. If a FileDescriptor\n" +" appears multiple times, the first occurrence\n" +" will be used.\n" " -oFILE, Writes a FileDescriptorSet (a protocol buffer,\n" " --descriptor_set_out=FILE defined in descriptor.proto) containing all of\n" " the input files to FILE.\n" @@ -1655,6 +1877,7 @@ bool CommandLineInterface::GeneratePluginOutput( request.set_parameter(parameter); } + std::set<const FileDescriptor*> already_seen; for (int i = 0; i < parsed_files.size(); i++) { request.add_file_to_generate(parsed_files[i]->name()); @@ -1823,24 +2046,24 @@ bool CommandLineInterface::WriteDescriptorSet( int fd; do { - fd = open(descriptor_set_name_.c_str(), + fd = open(descriptor_set_out_name_.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); } while (fd < 0 && errno == EINTR); if (fd < 0) { - perror(descriptor_set_name_.c_str()); + perror(descriptor_set_out_name_.c_str()); return false; } io::FileOutputStream out(fd); if (!file_set.SerializeToZeroCopyStream(&out)) { - std::cerr << descriptor_set_name_ << ": " << strerror(out.GetErrno()) + std::cerr << descriptor_set_out_name_ << ": " << strerror(out.GetErrno()) << std::endl; out.Close(); return false; } if (!out.Close()) { - std::cerr << descriptor_set_name_ << ": " << strerror(out.GetErrno()) + std::cerr << descriptor_set_out_name_ << ": " << strerror(out.GetErrno()) << std::endl; return false; } diff --git a/src/google/protobuf/compiler/command_line_interface.h b/src/google/protobuf/compiler/command_line_interface.h index 997c1748..e6596575 100644 --- a/src/google/protobuf/compiler/command_line_interface.h +++ b/src/google/protobuf/compiler/command_line_interface.h @@ -52,17 +52,16 @@ namespace protobuf { class Descriptor; // descriptor.h class DescriptorPool; // descriptor.h class FileDescriptor; // descriptor.h +class FileDescriptorSet; // descriptor.h class FileDescriptorProto; // descriptor.pb.h template<typename T> class RepeatedPtrField; // repeated_field.h +class SimpleDescriptorDatabase; // descriptor_database.h -} // namespace protobuf - -namespace protobuf { namespace compiler { -class CodeGenerator; // code_generator.h -class GeneratorContext; // code_generator.h -class DiskSourceTree; // importer.h +class CodeGenerator; // code_generator.h +class GeneratorContext; // code_generator.h +class DiskSourceTree; // importer.h // This class implements the command-line interface to the protocol compiler. // It is designed to make it very easy to create a custom protocol compiler @@ -91,9 +90,21 @@ class DiskSourceTree; // importer.h // The compiler is invoked with syntax like: // protoc --cpp_out=outdir --foo_out=outdir --proto_path=src src/foo.proto // +// The .proto file to compile can be specified on the command line using either +// its physical file path, or a virtual path relative to a diretory specified +// in --proto_path. For example, for src/foo.proto, the following two protoc +// invocations work the same way: +// 1. protoc --proto_path=src src/foo.proto (physical file path) +// 2. protoc --proto_path=src foo.proto (virtual path relative to src) +// +// If a file path can be interpreted both as a physical file path and as a +// relative virtual path, the physical file path takes precendence. +// // For a full description of the command-line syntax, invoke it with --help. class LIBPROTOC_EXPORT CommandLineInterface { public: + static const char* const kPathSeparator; + CommandLineInterface(); ~CommandLineInterface(); @@ -175,17 +186,11 @@ class LIBPROTOC_EXPORT CommandLineInterface { // it calls strerror(). I'm not sure why you'd want to do this anyway. int Run(int argc, const char* const argv[]); - // Call SetInputsAreCwdRelative(true) if the input files given on the command - // line should be interpreted relative to the proto import path specified - // using --proto_path or -I flags. Otherwise, input file names will be - // interpreted relative to the current working directory (or as absolute - // paths if they start with '/'), though they must still reside inside - // a directory given by --proto_path or the compiler will fail. The latter - // mode is generally more intuitive and easier to use, especially e.g. when - // defining implicit rules in Makefiles. - void SetInputsAreProtoPathRelative(bool enable) { - inputs_are_proto_path_relative_ = enable; - } + // DEPRECATED. Calling this method has no effect. Protocol compiler now + // always try to find the .proto file relative to the current directory + // first and if the file is not found, it will then treat the input path + // as a virutal path. + void SetInputsAreProtoPathRelative(bool /* enable */) {} // Provides some text which will be printed when the --version flag is // used. The version of libprotoc will also be printed on the next line @@ -243,6 +248,16 @@ class LIBPROTOC_EXPORT CommandLineInterface { // Print the --help text to stderr. void PrintHelpText(); + // Loads proto_path_ into the provided source_tree. + bool InitializeDiskSourceTree(DiskSourceTree* source_tree); + + // Loads descriptor_set_in into the provided database + bool PopulateSimpleDescriptorDatabase(SimpleDescriptorDatabase* database); + + // Parses input_files_ into parsed_files + bool ParseInputFiles(DescriptorPool* descriptor_pool, + std::vector<const FileDescriptor*>* parsed_files); + // Generate the given output file from the given input. struct OutputDirective; // see below bool GenerateOutput(const std::vector<const FileDescriptor*>& parsed_files, @@ -383,9 +398,13 @@ class LIBPROTOC_EXPORT CommandLineInterface { // decoding. (Empty string indicates --decode_raw.) string codec_type_; + // If --descriptor_set_in was given, these are filenames containing + // parsed FileDescriptorSets to be used for loading protos. Otherwise, empty. + std::vector<string> descriptor_set_in_names_; + // If --descriptor_set_out was given, this is the filename to which the // FileDescriptorSet should be written. Otherwise, empty. - string descriptor_set_name_; + string descriptor_set_out_name_; // If --dependency_out was given, this is the path to the file where the // dependency file will be written. Otherwise, empty. @@ -408,9 +427,6 @@ class LIBPROTOC_EXPORT CommandLineInterface { // Was the --disallow_services flag used? bool disallow_services_; - // See SetInputsAreProtoPathRelative(). - bool inputs_are_proto_path_relative_; - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(CommandLineInterface); }; diff --git a/src/google/protobuf/compiler/command_line_interface_unittest.cc b/src/google/protobuf/compiler/command_line_interface_unittest.cc index 366e623f..c4db7f99 100644 --- a/src/google/protobuf/compiler/command_line_interface_unittest.cc +++ b/src/google/protobuf/compiler/command_line_interface_unittest.cc @@ -35,6 +35,7 @@ #include <fcntl.h> #include <sys/stat.h> #include <sys/types.h> + #ifdef _MSC_VER #include <io.h> #else @@ -56,6 +57,7 @@ #include <google/protobuf/unittest.pb.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/io/zero_copy_stream.h> + #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.h> #include <google/protobuf/stubs/substitute.h> @@ -86,6 +88,7 @@ namespace compiler { #endif #endif + namespace { bool FileExists(const string& path) { @@ -129,10 +132,6 @@ class CommandLineInterfaceTest : public testing::Test { // google3. #endif // !PROTOBUF_OPENSOURCE - void SetInputsAreProtoPathRelative(bool enable) { - cli_.SetInputsAreProtoPathRelative(enable); - } - // ----------------------------------------------------------------- // Methods to check the test results (called after Run()). @@ -192,12 +191,17 @@ class CommandLineInterfaceTest : public testing::Test { const string& insertions, const string& proto_name, const string& message_name); + void CheckGeneratedAnnotations(const string& name, const string& file); void ExpectNullCodeGeneratorCalled(const string& parameter); + void ReadDescriptorSet(const string& filename, FileDescriptorSet* descriptor_set); + void WriteDescriptorSet(const string& filename, + const FileDescriptorSet* descriptor_set); + void ExpectFileContent(const string& filename, const string& content); @@ -251,11 +255,6 @@ class CommandLineInterfaceTest::NullCodeGenerator : public CodeGenerator { // =================================================================== void CommandLineInterfaceTest::SetUp() { - // Most of these tests were written before this option was added, so we - // run with the option on (which used to be the only way) except in certain - // tests where we turn it off. - cli_.SetInputsAreProtoPathRelative(true); - temp_directory_ = TestTempDir() + "/proto2_cli_test_temp"; // If the temp directory already exists, it must be left over from a @@ -281,6 +280,7 @@ void CommandLineInterfaceTest::SetUp() { mock_generators_to_delete_.push_back(generator); cli_.RegisterGenerator("--null_out", generator, "Null output."); + disallow_plugins_ = false; } @@ -471,12 +471,18 @@ void CommandLineInterfaceTest::ExpectGeneratedWithInsertions( proto_name, temp_directory_); } +void CommandLineInterfaceTest::CheckGeneratedAnnotations(const string& name, + const string& file) { + MockCodeGenerator::CheckGeneratedAnnotations(name, file, temp_directory_); +} + void CommandLineInterfaceTest::ExpectNullCodeGeneratorCalled( const string& parameter) { EXPECT_TRUE(null_generator_->called_); EXPECT_EQ(parameter, null_generator_->parameter_); } + void CommandLineInterfaceTest::ReadDescriptorSet( const string& filename, FileDescriptorSet* descriptor_set) { string path = temp_directory_ + "/" + filename; @@ -488,6 +494,13 @@ void CommandLineInterfaceTest::ReadDescriptorSet( } } +void CommandLineInterfaceTest::WriteDescriptorSet( + const string& filename, const FileDescriptorSet* descriptor_set) { + string binary_proto; + GOOGLE_CHECK(descriptor_set->SerializeToString(&binary_proto)); + CreateTempFile(filename, binary_proto); +} + void CommandLineInterfaceTest::ExpectCapturedStdout( const string& expected_text) { EXPECT_EQ(expected_text, captured_stdout_); @@ -496,7 +509,8 @@ void CommandLineInterfaceTest::ExpectCapturedStdout( void CommandLineInterfaceTest::ExpectCapturedStdoutSubstringWithZeroReturnCode( const string& expected_substring) { EXPECT_EQ(0, return_code_); - EXPECT_PRED_FORMAT2(testing::IsSubstring, expected_substring, captured_stdout_); + EXPECT_PRED_FORMAT2( + testing::IsSubstring, expected_substring, captured_stdout_); } void CommandLineInterfaceTest::ExpectFileContent( @@ -525,6 +539,22 @@ TEST_F(CommandLineInterfaceTest, BasicOutput) { ExpectGenerated("test_generator", "", "foo.proto", "Foo"); } +TEST_F(CommandLineInterfaceTest, BasicOutput_DescriptorSetIn) { + // Test that the common case works. + FileDescriptorSet file_descriptor_set; + FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("foo.proto"); + file_descriptor_proto->add_message_type()->set_name("Foo"); + + WriteDescriptorSet("foo.bin", &file_descriptor_set); + + Run("protocol_compiler --test_out=$tmpdir " + "--descriptor_set_in=$tmpdir/foo.bin foo.proto"); + + ExpectNoErrors(); + ExpectGenerated("test_generator", "", "foo.proto", "Foo"); +} + TEST_F(CommandLineInterfaceTest, BasicPlugin) { // Test that basic plugins work. @@ -539,6 +569,23 @@ TEST_F(CommandLineInterfaceTest, BasicPlugin) { ExpectGenerated("test_plugin", "", "foo.proto", "Foo"); } +TEST_F(CommandLineInterfaceTest, BasicPlugin_DescriptorSetIn) { + // Test that basic plugins work. + + FileDescriptorSet file_descriptor_set; + FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("foo.proto"); + file_descriptor_proto->add_message_type()->set_name("Foo"); + + WriteDescriptorSet("foo.bin", &file_descriptor_set); + + Run("protocol_compiler --plug_out=$tmpdir " + "--descriptor_set_in=$tmpdir/foo.bin foo.proto"); + + ExpectNoErrors(); + ExpectGenerated("test_plugin", "", "foo.proto", "Foo"); +} + TEST_F(CommandLineInterfaceTest, GeneratorAndPlugin) { // Invoke a generator and a plugin at the same time. @@ -554,6 +601,24 @@ TEST_F(CommandLineInterfaceTest, GeneratorAndPlugin) { ExpectGenerated("test_plugin", "", "foo.proto", "Foo"); } +TEST_F(CommandLineInterfaceTest, GeneratorAndPlugin_DescriptorSetIn) { + // Invoke a generator and a plugin at the same time. + + FileDescriptorSet file_descriptor_set; + FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("foo.proto"); + file_descriptor_proto->add_message_type()->set_name("Foo"); + + WriteDescriptorSet("foo.bin", &file_descriptor_set); + + Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir " + "--descriptor_set_in=$tmpdir/foo.bin foo.proto"); + + ExpectNoErrors(); + ExpectGenerated("test_generator", "", "foo.proto", "Foo"); + ExpectGenerated("test_plugin", "", "foo.proto", "Foo"); +} + TEST_F(CommandLineInterfaceTest, MultipleInputs) { // Test parsing multiple input files. @@ -578,6 +643,34 @@ TEST_F(CommandLineInterfaceTest, MultipleInputs) { "bar.proto", "Bar"); } +TEST_F(CommandLineInterfaceTest, MultipleInputs_DescriptorSetIn) { + // Test parsing multiple input files. + FileDescriptorSet file_descriptor_set; + + FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("foo.proto"); + file_descriptor_proto->add_message_type()->set_name("Foo"); + + file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("bar.proto"); + file_descriptor_proto->add_message_type()->set_name("Bar"); + + WriteDescriptorSet("foo.bin", &file_descriptor_set); + + Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir " + "--descriptor_set_in=$tmpdir/foo.bin foo.proto bar.proto"); + + ExpectNoErrors(); + ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto", + "foo.proto", "Foo"); + ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto", + "bar.proto", "Bar"); + ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto", + "foo.proto", "Foo"); + ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto", + "bar.proto", "Bar"); +} + TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport) { // Test parsing multiple input files with an import of a separate file. @@ -608,6 +701,165 @@ TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport) { "bar.proto", "Bar"); } +TEST_F(CommandLineInterfaceTest, MultipleInputsWithImport_DescriptorSetIn) { + // Test parsing multiple input files with an import of a separate file. + FileDescriptorSet file_descriptor_set; + + FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("foo.proto"); + file_descriptor_proto->add_message_type()->set_name("Foo"); + + file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("bar.proto"); + file_descriptor_proto->add_dependency("baz.proto"); + DescriptorProto* message = file_descriptor_proto->add_message_type(); + message->set_name("Bar"); + FieldDescriptorProto* field = message->add_field(); + field->set_type_name("Baz"); + field->set_name("a"); + field->set_number(1); + + WriteDescriptorSet("foo_and_bar.bin", &file_descriptor_set); + + file_descriptor_set.clear_file(); + file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("baz.proto"); + file_descriptor_proto->add_message_type()->set_name("Baz"); + + file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("bat.proto"); + file_descriptor_proto->add_dependency("baz.proto"); + message = file_descriptor_proto->add_message_type(); + message->set_name("Bat"); + field = message->add_field(); + field->set_type_name("Baz"); + field->set_name("a"); + field->set_number(1); + + WriteDescriptorSet("baz_and_bat.bin", &file_descriptor_set); + Run(strings::Substitute( + "protocol_compiler --test_out=$$tmpdir --plug_out=$$tmpdir " + "--descriptor_set_in=$0 foo.proto bar.proto", + string("$tmpdir/foo_and_bar.bin") + + CommandLineInterface::kPathSeparator + + "$tmpdir/baz_and_bat.bin")); + + ExpectNoErrors(); + ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto", + "foo.proto", "Foo"); + ExpectGeneratedWithMultipleInputs("test_generator", "foo.proto,bar.proto", + "bar.proto", "Bar"); + ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto", + "foo.proto", "Foo"); + ExpectGeneratedWithMultipleInputs("test_plugin", "foo.proto,bar.proto", + "bar.proto", "Bar"); + + Run(strings::Substitute( + "protocol_compiler --test_out=$$tmpdir --plug_out=$$tmpdir " + "--descriptor_set_in=$0 baz.proto bat.proto", + string("$tmpdir/foo_and_bar.bin") + + CommandLineInterface::kPathSeparator + + "$tmpdir/baz_and_bat.bin")); + + ExpectNoErrors(); + ExpectGeneratedWithMultipleInputs("test_generator", "baz.proto,bat.proto", + "baz.proto", "Baz"); + ExpectGeneratedWithMultipleInputs("test_generator", "baz.proto,bat.proto", + "bat.proto", "Bat"); + ExpectGeneratedWithMultipleInputs("test_plugin", "baz.proto,bat.proto", + "baz.proto", "Baz"); + ExpectGeneratedWithMultipleInputs("test_plugin", "baz.proto,bat.proto", + "bat.proto", "Bat"); +} + +TEST_F(CommandLineInterfaceTest, + MultipleInputsWithImport_DescriptorSetIn_DuplicateFileDescriptor) { + // Test parsing multiple input files with an import of a separate file. + FileDescriptorSet file_descriptor_set; + + FileDescriptorProto foo_file_descriptor_proto; + foo_file_descriptor_proto.set_name("foo.proto"); + foo_file_descriptor_proto.add_message_type()->set_name("Foo"); + + file_descriptor_set.add_file()->CopyFrom(foo_file_descriptor_proto); + + FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("bar.proto"); + file_descriptor_proto->add_dependency("baz.proto"); + file_descriptor_proto->add_dependency("foo.proto"); + DescriptorProto* message = file_descriptor_proto->add_message_type(); + message->set_name("Bar"); + FieldDescriptorProto* field = message->add_field(); + field->set_type_name("Baz"); + field->set_name("a"); + field->set_number(1); + field = message->add_field(); + field->set_type_name("Foo"); + field->set_name("f"); + field->set_number(2); + WriteDescriptorSet("foo_and_bar.bin", &file_descriptor_set); + + file_descriptor_set.clear_file(); + file_descriptor_set.add_file()->CopyFrom(foo_file_descriptor_proto); + + file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("baz.proto"); + file_descriptor_proto->add_dependency("foo.proto"); + message = file_descriptor_proto->add_message_type(); + message->set_name("Baz"); + field = message->add_field(); + field->set_type_name("Foo"); + field->set_name("f"); + field->set_number(1); + WriteDescriptorSet("foo_and_baz.bin", &file_descriptor_set); + + Run(strings::Substitute( + "protocol_compiler --test_out=$$tmpdir --plug_out=$$tmpdir " + "--descriptor_set_in=$0 bar.proto", + string("$tmpdir/foo_and_bar.bin") + + CommandLineInterface::kPathSeparator + + "$tmpdir/foo_and_baz.bin")); + + ExpectNoErrors(); + ExpectGenerated("test_generator", "", "bar.proto", "Bar"); + ExpectGenerated("test_plugin", "", "bar.proto", "Bar"); +} + +TEST_F(CommandLineInterfaceTest, + MultipleInputsWithImport_DescriptorSetIn_MissingImport) { + // Test parsing multiple input files with an import of a separate file. + FileDescriptorSet file_descriptor_set; + + FileDescriptorProto* file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("foo.proto"); + file_descriptor_proto->add_message_type()->set_name("Foo"); + + file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("bar.proto"); + file_descriptor_proto->add_dependency("baz.proto"); + DescriptorProto* message = file_descriptor_proto->add_message_type(); + message->set_name("Bar"); + FieldDescriptorProto* field = message->add_field(); + field->set_type_name("Baz"); + field->set_name("a"); + field->set_number(1); + + WriteDescriptorSet("foo_and_bar.bin", &file_descriptor_set); + + file_descriptor_set.clear_file(); + file_descriptor_proto = file_descriptor_set.add_file(); + file_descriptor_proto->set_name("baz.proto"); + file_descriptor_proto->add_message_type()->set_name("Baz"); + + WriteDescriptorSet("baz.bin", &file_descriptor_set); + Run("protocol_compiler --test_out=$tmpdir --plug_out=$tmpdir " + "--descriptor_set_in=$tmpdir/foo_and_bar.bin " + "foo.proto bar.proto"); + ExpectErrorSubstring( + "bar.proto: Import \"baz.proto\" was not found or had errors."); + ExpectErrorSubstring("bar.proto: \"Baz\" is not defined."); +} + TEST_F(CommandLineInterfaceTest, CreateDirectory) { // Test that when we output to a sub-directory, it is created. @@ -754,6 +1006,25 @@ TEST_F(CommandLineInterfaceTest, Insert) { "foo.proto", "Foo"); } +TEST_F(CommandLineInterfaceTest, InsertWithAnnotationFixup) { + // Check that annotation spans are updated after insertions. + + CreateTempFile("foo.proto", + "syntax = \"proto2\";\n" + "message MockCodeGenerator_Annotate {}\n"); + + Run("protocol_compiler " + "--test_out=TestParameter:$tmpdir " + "--plug_out=TestPluginParameter:$tmpdir " + "--test_out=insert=test_generator,test_plugin:$tmpdir " + "--plug_out=insert=test_generator,test_plugin:$tmpdir " + "--proto_path=$tmpdir foo.proto"); + + ExpectNoErrors(); + CheckGeneratedAnnotations("test_generator", "foo.proto"); + CheckGeneratedAnnotations("test_plugin", "foo.proto"); +} + #if defined(_WIN32) TEST_F(CommandLineInterfaceTest, WindowsOutputPath) { @@ -839,17 +1110,11 @@ TEST_F(CommandLineInterfaceTest, ColonDelimitedPath) { "}\n"); CreateTempFile("b/foo.proto", "this should not be parsed\n"); -#undef PATH_SEPARATOR -#if defined(_WIN32) -#define PATH_SEPARATOR ";" -#else -#define PATH_SEPARATOR ":" -#endif - - Run("protocol_compiler --test_out=$tmpdir " - "--proto_path=$tmpdir/a" PATH_SEPARATOR "$tmpdir/b foo.proto"); - -#undef PATH_SEPARATOR + Run(strings::Substitute( + "protocol_compiler --test_out=$$tmpdir --proto_path=$0 foo.proto", + string("$tmpdir/a") + + CommandLineInterface::kPathSeparator + + "$tmpdir/b")); ExpectNoErrors(); ExpectGenerated("test_generator", "", "foo.proto", "Foo"); @@ -1059,8 +1324,6 @@ TEST_F(CommandLineInterfaceTest, DirectDependencies_CustomErrorMessage) { TEST_F(CommandLineInterfaceTest, CwdRelativeInputs) { // Test that we can accept working-directory-relative input files. - SetInputsAreProtoPathRelative(false); - CreateTempFile("foo.proto", "syntax = \"proto2\";\n" "message Foo {}\n"); @@ -1318,6 +1581,17 @@ TEST_F(CommandLineInterfaceTest, ParseErrors) { "foo.proto:2:1: Expected top-level statement (e.g. \"message\").\n"); } +TEST_F(CommandLineInterfaceTest, ParseErrors_DescriptorSetIn) { + // Test that parse errors are reported. + CreateTempFile("foo.bin", "not a FileDescriptorSet"); + + Run("protocol_compiler --test_out=$tmpdir " + "--descriptor_set_in=$tmpdir/foo.bin foo.proto"); + + ExpectErrorText( + "$tmpdir/foo.bin: Unable to parse.\n"); +} + TEST_F(CommandLineInterfaceTest, ParseErrorsMultipleFiles) { // Test that parse errors are reported from multiple files. @@ -1364,16 +1638,23 @@ TEST_F(CommandLineInterfaceTest, InputNotFoundError) { Run("protocol_compiler --test_out=$tmpdir " "--proto_path=$tmpdir foo.proto"); + ExpectErrorText("foo.proto: No such file or directory\n"); +} + +TEST_F(CommandLineInterfaceTest, InputNotFoundError_DescriptorSetIn) { + // Test what happens if the input file is not found. + + Run("protocol_compiler --test_out=$tmpdir " + "--descriptor_set_in=$tmpdir/foo.bin foo.proto"); + ExpectErrorText( - "foo.proto: File not found.\n"); + "$tmpdir/foo.bin: No such file or directory\n"); } TEST_F(CommandLineInterfaceTest, CwdRelativeInputNotFoundError) { // Test what happens when a working-directory-relative input file is not // found. - SetInputsAreProtoPathRelative(false); - Run("protocol_compiler --test_out=$tmpdir " "--proto_path=$tmpdir $tmpdir/foo.proto"); @@ -1385,8 +1666,6 @@ TEST_F(CommandLineInterfaceTest, CwdRelativeInputNotMappedError) { // Test what happens when a working-directory-relative input file is not // mapped to a virtual path. - SetInputsAreProtoPathRelative(false); - CreateTempFile("foo.proto", "syntax = \"proto2\";\n" "message Foo {}\n"); @@ -1411,8 +1690,6 @@ TEST_F(CommandLineInterfaceTest, CwdRelativeInputNotFoundAndNotMappedError) { // Check what happens if the input file is not found *and* is not mapped // in the proto_path. - SetInputsAreProtoPathRelative(false); - // Create a directory called "bar" so that we can point --proto_path at it. CreateTempFile("bar/dummy", ""); @@ -1427,8 +1704,6 @@ TEST_F(CommandLineInterfaceTest, CwdRelativeInputShadowedError) { // Test what happens when a working-directory-relative input file is shadowed // by another file in the virtual path. - SetInputsAreProtoPathRelative(false); - CreateTempFile("foo/foo.proto", "syntax = \"proto2\";\n" "message Foo {}\n"); @@ -1454,8 +1729,34 @@ TEST_F(CommandLineInterfaceTest, ProtoPathNotFoundError) { "--proto_path=$tmpdir/foo foo.proto"); ExpectErrorText( - "$tmpdir/foo: warning: directory does not exist.\n" - "foo.proto: File not found.\n"); + "$tmpdir/foo: warning: directory does not exist.\n" + "foo.proto: No such file or directory\n"); +} + +TEST_F(CommandLineInterfaceTest, ProtoPathAndDescriptorSetIn) { + Run("protocol_compiler --test_out=$tmpdir " + "--proto_path=$tmpdir --descriptor_set_in=$tmpdir/foo.bin foo.proto"); + ExpectErrorText( + "Only one of --descriptor_set_in and --proto_path can be specified.\n"); + + Run("protocol_compiler --test_out=$tmpdir " + "--descriptor_set_in=$tmpdir/foo.bin --proto_path=$tmpdir foo.proto"); + ExpectErrorText( + "Only one of --proto_path and --descriptor_set_in can be specified.\n"); +} + +TEST_F(CommandLineInterfaceTest, ProtoPathAndDependencyOut) { + Run("protocol_compiler --test_out=$tmpdir " + "--dependency_out=$tmpdir/manifest " + "--descriptor_set_in=$tmpdir/foo.bin foo.proto"); + ExpectErrorText( + "--descriptor_set_in cannot be used with --dependency_out.\n"); + + Run("protocol_compiler --test_out=$tmpdir " + "--descriptor_set_in=$tmpdir/foo.bin " + "--dependency_out=$tmpdir/manifest foo.proto"); + ExpectErrorText( + "--dependency_out cannot be used with --descriptor_set_in.\n"); } TEST_F(CommandLineInterfaceTest, MissingInputError) { @@ -1905,9 +2206,16 @@ TEST_F(CommandLineInterfaceTest, PrintFreeFieldNumbers) { // test as a shell script, but we'd like to be able to run the test on // platforms that don't have a Bourne-compatible shell available (especially // Windows/MSVC). -class EncodeDecodeTest : public testing::Test { + +enum EncodeDecodeTestMode { + PROTO_PATH, + DESCRIPTOR_SET_IN +}; + +class EncodeDecodeTest : public testing::TestWithParam<EncodeDecodeTestMode> { protected: virtual void SetUp() { + WriteUnittestProtoDescriptorSet(); duped_stdin_ = dup(STDIN_FILENO); } @@ -1950,7 +2258,18 @@ class EncodeDecodeTest : public testing::Test { std::vector<string> args; args.push_back("protoc"); SplitStringUsing(command, " ", &args); - args.push_back("--proto_path=" + TestSourceDir()); + switch (GetParam()) { + case PROTO_PATH: + args.push_back("--proto_path=" + TestSourceDir()); + break; + case DESCRIPTOR_SET_IN: + args.push_back(StrCat( + "--descriptor_set_in=", + unittest_proto_descriptor_set_filename_)); + break; + default: + ADD_FAILURE() << "unexpected EncodeDecodeTestMode: " << GetParam(); + } google::protobuf::scoped_array<const char * > argv(new const char* [args.size()]); for (int i = 0; i < args.size(); i++) { @@ -1958,7 +2277,6 @@ class EncodeDecodeTest : public testing::Test { } CommandLineInterface cli; - cli.SetInputsAreProtoPathRelative(true); CaptureTestStdout(); CaptureTestStderr(); @@ -1996,12 +2314,37 @@ class EncodeDecodeTest : public testing::Test { } private: + void WriteUnittestProtoDescriptorSet() { + unittest_proto_descriptor_set_filename_ = + TestTempDir() + "/unittest_proto_descriptor_set.bin"; + FileDescriptorSet file_descriptor_set; + protobuf_unittest::TestAllTypes test_all_types; + test_all_types.descriptor()->file()->CopyTo(file_descriptor_set.add_file()); + + protobuf_unittest_import::ImportMessage import_message; + import_message.descriptor()->file()->CopyTo(file_descriptor_set.add_file()); + + + protobuf_unittest_import::PublicImportMessage public_import_message; + public_import_message.descriptor()->file()->CopyTo( + file_descriptor_set.add_file()); + GOOGLE_DCHECK(file_descriptor_set.IsInitialized()); + + string binary_proto; + GOOGLE_CHECK(file_descriptor_set.SerializeToString(&binary_proto)); + GOOGLE_CHECK_OK(File::SetContents( + unittest_proto_descriptor_set_filename_, + binary_proto, + true)); + } + int duped_stdin_; string captured_stdout_; string captured_stderr_; + string unittest_proto_descriptor_set_filename_; }; -TEST_F(EncodeDecodeTest, Encode) { +TEST_P(EncodeDecodeTest, Encode) { RedirectStdinFromFile(TestSourceDir() + "/google/protobuf/" "testdata/text_format_unittest_data_oneof_implemented.txt"); EXPECT_TRUE(Run("google/protobuf/unittest.proto " @@ -2011,7 +2354,7 @@ TEST_F(EncodeDecodeTest, Encode) { ExpectStderrMatchesText(""); } -TEST_F(EncodeDecodeTest, Decode) { +TEST_P(EncodeDecodeTest, Decode) { RedirectStdinFromFile(TestSourceDir() + "/google/protobuf/testdata/golden_message_oneof_implemented"); EXPECT_TRUE(Run("google/protobuf/unittest.proto " @@ -2022,7 +2365,7 @@ TEST_F(EncodeDecodeTest, Decode) { ExpectStderrMatchesText(""); } -TEST_F(EncodeDecodeTest, Partial) { +TEST_P(EncodeDecodeTest, Partial) { RedirectStdinFromText(""); EXPECT_TRUE(Run("google/protobuf/unittest.proto " "--encode=protobuf_unittest.TestRequired")); @@ -2031,7 +2374,7 @@ TEST_F(EncodeDecodeTest, Partial) { "warning: Input message is missing required fields: a, b, c\n"); } -TEST_F(EncodeDecodeTest, DecodeRaw) { +TEST_P(EncodeDecodeTest, DecodeRaw) { protobuf_unittest::TestAllTypes message; message.set_optional_int32(123); message.set_optional_string("foo"); @@ -2045,21 +2388,24 @@ TEST_F(EncodeDecodeTest, DecodeRaw) { ExpectStderrMatchesText(""); } -TEST_F(EncodeDecodeTest, UnknownType) { +TEST_P(EncodeDecodeTest, UnknownType) { EXPECT_FALSE(Run("google/protobuf/unittest.proto " "--encode=NoSuchType")); ExpectStdoutMatchesText(""); ExpectStderrMatchesText("Type not defined: NoSuchType\n"); } -TEST_F(EncodeDecodeTest, ProtoParseError) { +TEST_P(EncodeDecodeTest, ProtoParseError) { EXPECT_FALSE(Run("google/protobuf/no_such_file.proto " "--encode=NoSuchType")); ExpectStdoutMatchesText(""); ExpectStderrMatchesText( - "google/protobuf/no_such_file.proto: File not found.\n"); + "google/protobuf/no_such_file.proto: No such file or directory\n"); } +INSTANTIATE_TEST_CASE_P(FileDescriptorSetSource, + EncodeDecodeTest, + testing::Values(PROTO_PATH, DESCRIPTOR_SET_IN)); } // anonymous namespace #endif // !GOOGLE_PROTOBUF_HEAP_CHECK_DRACONIAN diff --git a/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc index fce58c02..f99159f5 100644 --- a/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/cpp/cpp_bootstrap_unittest.cc @@ -125,12 +125,9 @@ TEST(BootstrapTest, GeneratedDescriptorMatches) { importer.Import("google/protobuf/descriptor.proto"); const FileDescriptor* plugin_proto_file = importer.Import("google/protobuf/compiler/plugin.proto"); - const FileDescriptor* profile_proto_file = - importer.Import("google/protobuf/compiler/profile.proto"); EXPECT_EQ("", error_collector.text_); ASSERT_TRUE(proto_file != NULL); ASSERT_TRUE(plugin_proto_file != NULL); - ASSERT_TRUE(profile_proto_file != NULL); CppGenerator generator; MockGeneratorContext context; @@ -141,8 +138,6 @@ TEST(BootstrapTest, GeneratedDescriptorMatches) { parameter = "dllexport_decl=LIBPROTOC_EXPORT"; ASSERT_TRUE(generator.Generate(plugin_proto_file, parameter, &context, &error)); - ASSERT_TRUE(generator.Generate(profile_proto_file, parameter, - &context, &error)); context.ExpectFileMatches("google/protobuf/descriptor.pb.h", "google/protobuf/descriptor.pb.h"); @@ -152,10 +147,6 @@ TEST(BootstrapTest, GeneratedDescriptorMatches) { "google/protobuf/compiler/plugin.pb.h"); context.ExpectFileMatches("google/protobuf/compiler/plugin.pb.cc", "google/protobuf/compiler/plugin.pb.cc"); - context.ExpectFileMatches("google/protobuf/compiler/profile.pb.h", - "google/protobuf/compiler/profile.pb.h"); - context.ExpectFileMatches("google/protobuf/compiler/profile.pb.cc", - "google/protobuf/compiler/profile.pb.cc"); } } // namespace diff --git a/src/google/protobuf/compiler/cpp/cpp_enum.cc b/src/google/protobuf/compiler/cpp/cpp_enum.cc index 6a8a83d1..3b4b97e6 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum.cc @@ -81,10 +81,16 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) { std::map<string, string> vars; vars["classname"] = classname_; vars["short_name"] = descriptor_->name(); - vars["enumbase"] = classname_ + (options_.proto_h ? " : int" : ""); - - printer->Print(vars, "enum $enumbase$ {\n"); - printer->Annotate("enumbase", descriptor_); + vars["enumbase"] = options_.proto_h ? " : int" : ""; + // These variables are placeholders to pick out the beginning and ends of + // identifiers for annotations (when doing so with existing variables would + // be ambiguous or impossible). They should never be set to anything but the + // empty string. + vars["{"] = ""; + vars["}"] = ""; + + printer->Print(vars, "enum $classname$$enumbase$ {\n"); + printer->Annotate("classname", descriptor_); printer->Indent(); const EnumValueDescriptor* min_value = descriptor_->value(0); @@ -102,7 +108,8 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) { " PROTOBUF_DEPRECATED" : ""; if (i > 0) printer->Print(",\n"); - printer->Print(vars, "$prefix$$name$$deprecation$ = $number$"); + printer->Print(vars, "${$$prefix$$name$$}$$deprecation$ = $number$"); + printer->Annotate("{", "}", descriptor_->value(i)); if (descriptor_->value(i)->number() < min_value->number()) { min_value = descriptor_->value(i); @@ -134,14 +141,20 @@ void EnumGenerator::GenerateDefinition(io::Printer* printer) { } printer->Print(vars, - "$dllexport$bool $classname$_IsValid(int value);\n" - "const $classname$ $prefix$$short_name$_MIN = $prefix$$min_name$;\n" - "const $classname$ $prefix$$short_name$_MAX = $prefix$$max_name$;\n"); + "$dllexport$bool $classname$_IsValid(int value);\n" + "const $classname$ ${$$prefix$$short_name$_MIN$}$ = " + "$prefix$$min_name$;\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(vars, + "const $classname$ ${$$prefix$$short_name$_MAX$}$ = " + "$prefix$$max_name$;\n"); + printer->Annotate("{", "}", descriptor_); if (generate_array_size_) { printer->Print(vars, - "const int $prefix$$short_name$_ARRAYSIZE = " - "$prefix$$short_name$_MAX + 1;\n\n"); + "const int ${$$prefix$$short_name$_ARRAYSIZE$}$ = " + "$prefix$$short_name$_MAX + 1;\n\n"); + printer->Annotate("{", "}", descriptor_); } if (HasDescriptorMethods(descriptor_->file(), options_)) { diff --git a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc index c15be942..e99e7e55 100644 --- a/src/google/protobuf/compiler/cpp/cpp_enum_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_enum_field.cc @@ -74,9 +74,11 @@ GeneratePrivateMembers(io::Printer* printer) const { void EnumFieldGenerator:: GenerateAccessorDeclarations(io::Printer* printer) const { + printer->Print(variables_, "$deprecated_attr$$type$ $name$() const;\n"); + printer->Annotate("name", descriptor_); printer->Print(variables_, - "$deprecated_attr$$type$ $name$() const;\n" - "$deprecated_attr$void set_$name$($type$ value);\n"); + "$deprecated_attr$void ${$set_$name$$}$($type$ value);\n"); + printer->Annotate("{", "}", descriptor_); } void EnumFieldGenerator:: @@ -113,7 +115,7 @@ GenerateMergingCode(io::Printer* printer) const { void EnumFieldGenerator:: GenerateSwappingCode(io::Printer* printer) const { - printer->Print(variables_, "std::swap($name$_, other->$name$_);\n"); + printer->Print(variables_, "swap($name$_, other->$name$_);\n"); } void EnumFieldGenerator:: @@ -257,12 +259,23 @@ GeneratePrivateMembers(io::Printer* printer) const { void RepeatedEnumFieldGenerator:: GenerateAccessorDeclarations(io::Printer* printer) const { printer->Print(variables_, - "$deprecated_attr$$type$ $name$(int index) const;\n" - "$deprecated_attr$void set_$name$(int index, $type$ value);\n" - "$deprecated_attr$void add_$name$($type$ value);\n"); + "$deprecated_attr$$type$ $name$(int index) const;\n"); + printer->Annotate("name", descriptor_); + printer->Print( + variables_, + "$deprecated_attr$void ${$set_$name$$}$(int index, $type$ value);\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "$deprecated_attr$void ${$add_$name$$}$($type$ value);\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print( + variables_, + "$deprecated_attr$const ::google::protobuf::RepeatedField<int>& $name$() const;\n"); + printer->Annotate("name", descriptor_); printer->Print(variables_, - "$deprecated_attr$const ::google::protobuf::RepeatedField<int>& $name$() const;\n" - "$deprecated_attr$::google::protobuf::RepeatedField<int>* mutable_$name$();\n"); + "$deprecated_attr$::google::protobuf::RepeatedField<int>* " + "${$mutable_$name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); } void RepeatedEnumFieldGenerator:: @@ -292,8 +305,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, printer->Print(variables, " $name$_.Add(value);\n" " // @@protoc_insertion_point(field_add:$full_name$)\n" - "}\n"); - printer->Print(variables, + "}\n" "$inline$const ::google::protobuf::RepeatedField<int>&\n" "$classname$::$name$() const {\n" " // @@protoc_insertion_point(field_list:$full_name$)\n" diff --git a/src/google/protobuf/compiler/cpp/cpp_extension.cc b/src/google/protobuf/compiler/cpp/cpp_extension.cc index e4fce461..6b1673b2 100644 --- a/src/google/protobuf/compiler/cpp/cpp_extension.cc +++ b/src/google/protobuf/compiler/cpp/cpp_extension.cc @@ -35,9 +35,10 @@ #include <google/protobuf/compiler/cpp/cpp_extension.h> #include <map> #include <google/protobuf/compiler/cpp/cpp_helpers.h> -#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/io/printer.h> #include <google/protobuf/descriptor.pb.h> +#include <google/protobuf/stubs/strutil.h> + namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/cpp/cpp_field.cc b/src/google/protobuf/compiler/cpp/cpp_field.cc index 4480a9d2..dce9617c 100644 --- a/src/google/protobuf/compiler/cpp/cpp_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_field.cc @@ -95,6 +95,13 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, // By default, empty string, so that generic code used for both oneofs and // singular fields can be written. (*variables)["oneof_prefix"] = ""; + + // These variables are placeholders to pick out the beginning and ends of + // identifiers for annotations (when doing so with existing variables would + // be ambiguous or impossible). They should never be set to anything but the + // empty string. + (*variables)["{"] = ""; + (*variables)["}"] = ""; } void SetCommonOneofFieldVariables(const FieldDescriptor* descriptor, @@ -194,7 +201,6 @@ const FieldGenerator& FieldGeneratorMap::get( return *field_generators_[field->index()]; } - } // namespace cpp } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/cpp/cpp_field.h b/src/google/protobuf/compiler/cpp/cpp_field.h index 00dc25d4..d9dd3850 100644 --- a/src/google/protobuf/compiler/cpp/cpp_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_field.h @@ -180,10 +180,6 @@ class FieldGenerator { virtual void GenerateDefaultInstanceAllocator(io::Printer* /*printer*/) const {} - // Generate code that should be run when ShutdownProtobufLibrary() is called, - // to delete all dynamically-allocated objects. - virtual void GenerateShutdownCode(io::Printer* /*printer*/) const {} - // Generate lines to decode this field, which will be placed inside the // message's MergeFromCodedStream() method. virtual void GenerateMergeFromCodedStream(io::Printer* printer) const = 0; @@ -233,7 +229,6 @@ class FieldGeneratorMap { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); }; - } // namespace cpp } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/cpp/cpp_file.cc b/src/google/protobuf/compiler/cpp/cpp_file.cc index e0542ae8..c56e26f7 100644 --- a/src/google/protobuf/compiler/cpp/cpp_file.cc +++ b/src/google/protobuf/compiler/cpp/cpp_file.cc @@ -126,12 +126,20 @@ FileGenerator::FileGenerator(const FileDescriptor* file, const Options& options) new EnumGenerator(file->enum_type(i), options)); enum_generators_.push_back(enum_generators_owner_[i].get()); } + for (int i = 0; i < enum_generators_.size(); i++) { + enum_generators_[i]->index_in_metadata_ = i; + } for (int i = 0; i < file->service_count(); i++) { service_generators_owner_[i].reset( new ServiceGenerator(file->service(i), options)); service_generators_.push_back(service_generators_owner_[i].get()); } + if (HasGenericServices(file_, options_)) { + for (int i = 0; i < service_generators_.size(); i++) { + service_generators_[i]->index_in_metadata_ = i; + } + } for (int i = 0; i < file->extension_count(); i++) { extension_generators_owner_[i].reset( @@ -526,11 +534,10 @@ class FileGenerator::ForwardDeclarations { void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { // AddDescriptors() is a file-level procedure which adds the encoded // FileDescriptorProto for this .proto file to the global DescriptorPool for - // generated files (DescriptorPool::generated_pool()). It either runs at - // static initialization time (by default) or when default_instance() is - // called for the first time (in LITE_RUNTIME mode with - // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER flag enabled). This procedure also - // constructs default instances and registers extensions. + // generated files (DescriptorPool::generated_pool()). It ordinarily runs at + // static initialization time, but is not used at all in LITE_RUNTIME mode + // except when extensions are used. This procedure also constructs default + // instances and registers extensions. // // Its sibling, AssignDescriptors(), actually pulls the compiled // FileDescriptor from the DescriptorPool and uses it to populate all of @@ -546,7 +553,8 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { // table-driven parsing. printer->Print("PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField\n" - " const TableStruct::entries[] = {\n"); + " const TableStruct::entries[] " + "GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n"); printer->Indent(); std::vector<size_t> entries; @@ -567,7 +575,8 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { "};\n" "\n" "PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField\n" - " const TableStruct::aux[] = {\n"); + " const TableStruct::aux[] " + "GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n"); printer->Indent(); std::vector<size_t> aux_entries; @@ -586,7 +595,8 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { printer->Print( "};\n" "PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const\n" - " TableStruct::schema[] = {\n"); + " TableStruct::schema[] " + "GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n"); printer->Indent(); size_t offset = 0; @@ -606,9 +616,47 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { "};\n" "\n"); + if (!message_generators_.empty() && options_.table_driven_serialization) { + printer->Print( + "const ::google::protobuf::internal::FieldMetadata TableStruct::field_metadata[] " + "= {\n"); + printer->Indent(); + std::vector<int> field_metadata_offsets; + int idx = 0; + for (int i = 0; i < message_generators_.size(); i++) { + field_metadata_offsets.push_back(idx); + idx += message_generators_[i]->GenerateFieldMetadata(printer); + } + field_metadata_offsets.push_back(idx); + printer->Outdent(); + printer->Print( + "};\n" + "const ::google::protobuf::internal::SerializationTable " + "TableStruct::serialization_table[] = {\n"); + printer->Indent(); + // We rely on the order we layout the tables to match the order we + // calculate them with FlattenMessagesInFile, so we check here that + // these match exactly. + std::vector<const Descriptor*> calculated_order = + FlattenMessagesInFile(file_); + GOOGLE_CHECK_EQ(calculated_order.size(), message_generators_.size()); + for (int i = 0; i < message_generators_.size(); i++) { + GOOGLE_CHECK_EQ(calculated_order[i], message_generators_[i]->descriptor_); + printer->Print( + "{$num_fields$, TableStruct::field_metadata + $index$},\n", + "classname", message_generators_[i]->classname_, "num_fields", + SimpleItoa(field_metadata_offsets[i + 1] - field_metadata_offsets[i]), + "index", SimpleItoa(field_metadata_offsets[i])); + } + printer->Outdent(); + printer->Print( + "};\n" + "\n"); + } if (HasDescriptorMethods(file_, options_)) { if (!message_generators_.empty()) { - printer->Print("const ::google::protobuf::uint32 TableStruct::offsets[] = {\n"); + printer->Print("const ::google::protobuf::uint32 TableStruct::offsets[] " + "GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n"); printer->Indent(); std::vector<std::pair<size_t, size_t> > pairs; for (int i = 0; i < message_generators_.size(); i++) { @@ -617,8 +665,8 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { printer->Outdent(); printer->Print( "};\n" - "\n" - "static const ::google::protobuf::internal::MigrationSchema schemas[] = {\n"); + "static const ::google::protobuf::internal::MigrationSchema schemas[] " + "GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n"); printer->Indent(); { int offset = 0; @@ -649,7 +697,7 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { // we still need these symbols to exist printer->Print( // MSVC doesn't like empty arrays, so we add a dummy. - "const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u };\n" + "const ::google::protobuf::uint32 TableStruct::offsets[1] = {};\n" "static const ::google::protobuf::internal::MigrationSchema* schemas = NULL;\n" "static const ::google::protobuf::Message* const* " "file_default_instances = NULL;\n"); @@ -739,33 +787,6 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { "} // namespace\n"); } - // ----------------------------------------------------------------- - - // ShutdownFile(): Deletes descriptors, default instances, etc. on shutdown. - printer->Print( - "\n" - "void TableStruct::Shutdown() {\n"); - printer->Indent(); - - for (int i = 0; i < message_generators_.size(); i++) { - message_generators_[i]->GenerateShutdownCode(printer); - } - - if (HasDescriptorMethods(file_, options_)) { - for (int i = 0; i < message_generators_.size(); i++) { - if (!IsMapEntryMessage(message_generators_[i]->descriptor_)) continue; - printer->Print( - "delete file_level_metadata[$index$].reflection;\n", - "index", SimpleItoa(i)); - } - } - - printer->Outdent(); - printer->Print( - "}\n\n"); - - // ----------------------------------------------------------------- - // Now generate the InitDefaultsImpl() function. printer->Print( "void TableStruct::InitDefaultsImpl() {\n" @@ -826,7 +847,8 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { string file_data; file_proto.SerializeToString(&file_data); - printer->Print("static const char descriptor[] = {\n"); + printer->Print("static const char descriptor[] " + "GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = {\n"); printer->Indent(); if (file_data.size() > 66535) { @@ -877,9 +899,6 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { file_namespace); } - printer->Print( - "::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown);\n"); - printer->Outdent(); printer->Print( "}\n" @@ -889,19 +908,15 @@ void FileGenerator::GenerateBuildDescriptors(io::Printer* printer) { " ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl);\n" "}\n"); - if (!StaticInitializersForced(file_, options_)) { - printer->Print("#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n"); - } - printer->Print( - // With static initializers. - "// Force AddDescriptors() to be called at static initialization time.\n" - "struct StaticDescriptorInitializer {\n" - " StaticDescriptorInitializer() {\n" - " AddDescriptors();\n" - " }\n" - "} static_descriptor_initializer;\n"); - if (!StaticInitializersForced(file_, options_)) { - printer->Print("#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n"); + if (StaticInitializersForced(file_, options_)) { + printer->Print( + "// Force AddDescriptors() to be called at dynamic initialization " + "time.\n" + "struct StaticDescriptorInitializer {\n" + " StaticDescriptorInitializer() {\n" + " AddDescriptors();\n" + " }\n" + "} static_descriptor_initializer;\n"); } } @@ -925,19 +940,11 @@ void FileGenerator::GenerateNamespaceClosers(io::Printer* printer) { void FileGenerator::GenerateForwardDeclarations(io::Printer* printer) { ForwardDeclarations decls; - for (int i = 0; i < file_->dependency_count(); i++) { - FileGenerator dependency(file_->dependency(i), options_); - dependency.FillForwardDeclarations(&decls); - } FillForwardDeclarations(&decls); decls.Print(printer, options_); } void FileGenerator::FillForwardDeclarations(ForwardDeclarations* decls) { - for (int i = 0; i < file_->public_dependency_count(); i++) { - FileGenerator dependency(file_->public_dependency(i), options_); - dependency.FillForwardDeclarations(decls); - } for (int i = 0; i < package_parts_.size(); i++) { decls = decls->AddOrGetNamespace(package_parts_[i]); } @@ -1033,11 +1040,11 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* printer) { "#include <google/protobuf/map.h>" " // IWYU pragma: export\n"); if (HasDescriptorMethods(file_, options_)) { - printer->Print( - "#include <google/protobuf/map_field_inl.h>\n"); + printer->Print("#include <google/protobuf/map_entry.h>\n"); + printer->Print("#include <google/protobuf/map_field_inl.h>\n"); } else { - printer->Print( - "#include <google/protobuf/map_field_lite.h>\n"); + printer->Print("#include <google/protobuf/map_entry_lite.h>\n"); + printer->Print("#include <google/protobuf/map_field_lite.h>\n"); } } @@ -1104,7 +1111,7 @@ void FileGenerator::GenerateDependencyIncludes(io::Printer* printer) { void FileGenerator::GenerateGlobalStateFunctionDeclarations( io::Printer* printer) { - // Forward-declare the AddDescriptors, AssignDescriptors, and ShutdownFile + // Forward-declare the AddDescriptors, AssignDescriptors // functions, so that we can declare them to be friends of each class. printer->Print( "\n" @@ -1115,12 +1122,14 @@ void FileGenerator::GenerateGlobalStateFunctionDeclarations( " static const ::google::protobuf::internal::AuxillaryParseTableField aux[];\n" " static const ::google::protobuf::internal::ParseTable schema[];\n" " static const ::google::protobuf::uint32 offsets[];\n" + " static const ::google::protobuf::internal::FieldMetadata field_metadata[];\n" + " static const ::google::protobuf::internal::SerializationTable " + "serialization_table[];\n" // The following function(s) need to be able to access private members of // the messages defined in the file. So we make them static members. // This is the internal implementation of InitDefaults. It should only // be called by InitDefaults which makes sure it will be called only once. " static void InitDefaultsImpl();\n" - " static void Shutdown();\n" "};\n" "void $dllexport_decl$AddDescriptors();\n" "void $dllexport_decl$InitDefaults();\n" @@ -1210,6 +1219,13 @@ void FileGenerator::GenerateInlineFunctionDefinitions(io::Printer* printer) { // dependent. printer->Print("#if !PROTOBUF_INLINE_NOT_IN_HEADERS\n"); + // TODO(gerbens) remove pragmas when gcc is no longer used. Current version + // of gcc fires a bogus error when compiled with strict-aliasing. + printer->Print( + "#ifdef __GNUC__\n" + " #pragma GCC diagnostic push\n" + " #pragma GCC diagnostic ignored \"-Wstrict-aliasing\"\n" + "#endif // __GNUC__\n"); // Generate class inline methods. for (int i = 0; i < message_generators_.size(); i++) { if (i > 0) { @@ -1219,6 +1235,10 @@ void FileGenerator::GenerateInlineFunctionDefinitions(io::Printer* printer) { message_generators_[i]->GenerateInlineMethods(printer, /* is_inline = */ true); } + printer->Print( + "#ifdef __GNUC__\n" + " #pragma GCC diagnostic pop\n" + "#endif // __GNUC__\n"); printer->Print("#endif // !PROTOBUF_INLINE_NOT_IN_HEADERS\n"); for (int i = 0; i < message_generators_.size(); i++) { @@ -1235,13 +1255,8 @@ void FileGenerator::GenerateProto2NamespaceEnumSpecializations( io::Printer* printer) { // Emit GetEnumDescriptor specializations into google::protobuf namespace: if (HasEnumDefinitions(file_)) { - // The SWIG conditional is to avoid a null-pointer dereference - // (bug 1984964) in swig-1.3.21 resulting from the following syntax: - // namespace X { void Y<Z::W>(); } - // which appears in GetEnumDescriptor() specializations. printer->Print( "\n" - "#ifndef SWIG\n" "namespace google {\nnamespace protobuf {\n" "\n"); for (int i = 0; i < enum_generators_.size(); i++) { @@ -1249,8 +1264,7 @@ void FileGenerator::GenerateProto2NamespaceEnumSpecializations( } printer->Print( "\n" - "} // namespace protobuf\n} // namespace google\n" - "#endif // SWIG\n"); + "} // namespace protobuf\n} // namespace google\n"); } } diff --git a/src/google/protobuf/compiler/cpp/cpp_generator.cc b/src/google/protobuf/compiler/cpp/cpp_generator.cc index cee31224..68abd0ef 100644 --- a/src/google/protobuf/compiler/cpp/cpp_generator.cc +++ b/src/google/protobuf/compiler/cpp/cpp_generator.cc @@ -100,6 +100,8 @@ bool CppGenerator::Generate(const FileDescriptor* file, file_options.enforce_lite = true; } else if (options[i].first == "table_driven_parsing") { file_options.table_driven_parsing = true; + } else if (options[i].first == "table_driven_serialization") { + file_options.table_driven_serialization = true; } else { *error = "Unknown generator option: " + options[i].first; return false; diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.cc b/src/google/protobuf/compiler/cpp/cpp_helpers.cc index 9cddba5c..00959796 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.cc +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.cc @@ -37,14 +37,16 @@ #include <vector> #include <google/protobuf/stubs/hash.h> -#include <google/protobuf/compiler/cpp/cpp_helpers.h> -#include <google/protobuf/io/printer.h> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> +#include <google/protobuf/compiler/cpp/cpp_helpers.h> +#include <google/protobuf/io/printer.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> + + namespace google { namespace protobuf { namespace compiler { @@ -167,6 +169,11 @@ string ClassName(const EnumDescriptor* enum_descriptor, bool qualified) { } } +string DefaultInstanceName(const Descriptor* descriptor) { + string prefix = descriptor->file()->package().empty() ? "" : "::"; + return prefix + DotsToColons(descriptor->file()->package()) + "::_" + + ClassName(descriptor, false) + "_default_instance_"; +} string DependentBaseClassTemplateName(const Descriptor* descriptor) { return ClassName(descriptor, false) + "_InternalBase"; @@ -654,6 +661,26 @@ void GenerateUtf8CheckCodeForCord(const FieldDescriptor* field, "VerifyUtf8Cord", "VerifyUTF8CordNamedField", printer); } +namespace { + +void Flatten(const Descriptor* descriptor, + std::vector<const Descriptor*>* flatten) { + for (int i = 0; i < descriptor->nested_type_count(); i++) + Flatten(descriptor->nested_type(i), flatten); + flatten->push_back(descriptor); +} + +} // namespace + +std::vector<const Descriptor*> FlattenMessagesInFile( + const FileDescriptor* file) { + std::vector<const Descriptor*> result; + for (int i = 0; i < file->message_type_count(); i++) { + Flatten(file->message_type(i), &result); + } + return result; +} + bool HasWeakFields(const Descriptor* descriptor) { return false; } diff --git a/src/google/protobuf/compiler/cpp/cpp_helpers.h b/src/google/protobuf/compiler/cpp/cpp_helpers.h index a744a865..6ae68591 100644 --- a/src/google/protobuf/compiler/cpp/cpp_helpers.h +++ b/src/google/protobuf/compiler/cpp/cpp_helpers.h @@ -67,6 +67,9 @@ extern const char kThinSeparator[]; string ClassName(const Descriptor* descriptor, bool qualified); string ClassName(const EnumDescriptor* enum_descriptor, bool qualified); +// Fully qualified name of the default_instance of this message. +string DefaultInstanceName(const Descriptor* descriptor); + // Name of the CRTP class template (for use with proto_h). // This is a class name, like "ProtoName_InternalBase". string DependentBaseClassTemplateName(const Descriptor* descriptor); @@ -159,8 +162,18 @@ string SafeFunctionName(const Descriptor* descriptor, const FieldDescriptor* field, const string& prefix); -// Returns true if unknown fields are preseved after parsing. -inline bool PreserveUnknownFields(const Descriptor* message) { +// Returns true if unknown fields are always preserved after parsing. +inline bool AlwaysPreserveUnknownFields(const FileDescriptor* file) { + return file->syntax() != FileDescriptor::SYNTAX_PROTO3; +} + +// Returns true if unknown fields are preserved after parsing. +inline bool AlwaysPreserveUnknownFields(const Descriptor* message) { + return AlwaysPreserveUnknownFields(message->file()); +} + +// Returns true if generated messages have public unknown fields accessors +inline bool PublicUnknownFieldsAccessors(const Descriptor* message) { return message->file()->syntax() != FileDescriptor::SYNTAX_PROTO3; } @@ -168,10 +181,8 @@ inline bool PreserveUnknownFields(const Descriptor* message) { ::google::protobuf::FileOptions_OptimizeMode GetOptimizeFor( const FileDescriptor* file, const Options& options); -// If PreserveUnknownFields() is true, determines whether unknown -// fields will be stored in an UnknownFieldSet or a string. -// If PreserveUnknownFields() is false, this method will not be -// used. +// Determines whether unknown fields will be stored in an UnknownFieldSet or +// a string. inline bool UseUnknownFieldSet(const FileDescriptor* file, const Options& options) { return GetOptimizeFor(file, options) != FileOptions::LITE_RUNTIME; @@ -277,6 +288,10 @@ inline ::google::protobuf::FileOptions_OptimizeMode GetOptimizeFor( : file->options().optimize_for(); } +// This orders the messages in a .pb.cc as it's outputted by file.cc +std::vector<const Descriptor*> FlattenMessagesInFile( + const FileDescriptor* file); + bool HasWeakFields(const Descriptor* desc); bool HasWeakFields(const FileDescriptor* desc); diff --git a/src/google/protobuf/compiler/cpp/cpp_map_field.cc b/src/google/protobuf/compiler/cpp/cpp_map_field.cc index 52a3b8b0..5d461401 100644 --- a/src/google/protobuf/compiler/cpp/cpp_map_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_map_field.cc @@ -150,6 +150,7 @@ GeneratePrivateMembers(io::Printer* printer) const { " $map_classname$;\n"); } printer->Print(variables_, + "private:\n" "::google::protobuf::internal::MapField$lite$<\n" " $map_classname$,\n" " $key_cpp$, $val_cpp$,\n" @@ -161,11 +162,15 @@ GeneratePrivateMembers(io::Printer* printer) const { void MapFieldGenerator:: GenerateAccessorDeclarations(io::Printer* printer) const { - printer->Print(variables_, + printer->Print( + variables_, "$deprecated_attr$const ::google::protobuf::Map< $key_cpp$, $val_cpp$ >&\n" - " $name$() const;\n" - "$deprecated_attr$::google::protobuf::Map< $key_cpp$, $val_cpp$ >*\n" - " mutable_$name$();\n"); + " $name$() const;\n"); + printer->Annotate("name", descriptor_); + printer->Print(variables_, + "$deprecated_attr$::google::protobuf::Map< $key_cpp$, $val_cpp$ >*\n" + " ${$mutable_$name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); } void MapFieldGenerator:: diff --git a/src/google/protobuf/compiler/cpp/cpp_message.cc b/src/google/protobuf/compiler/cpp/cpp_message.cc index d9524f64..752673d0 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message.cc @@ -52,6 +52,8 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/generated_message_table_driven.h> +#include <google/protobuf/generated_message_util.h> +#include <google/protobuf/map_entry_lite.h> #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> @@ -280,7 +282,7 @@ void OptimizePadding(std::vector<const FieldDescriptor*>* fields, enum Family { REPEATED = 0, STRING = 1, - MESSAGE = 2, + MESSAGE = 3, ZERO_INITIALIZABLE = 4, OTHER = 5, kMaxFamily @@ -452,22 +454,13 @@ bool HasPrivateHasMethod(const FieldDescriptor* field) { } -bool TableDrivenEnabled(const Descriptor* descriptor, const Options& options) { +bool TableDrivenParsingEnabled( + const Descriptor* descriptor, const Options& options) { if (!options.table_driven_parsing) { return false; } // Consider table-driven parsing. We only do this if: - // - There are no extensions - if (descriptor->extension_range_count() != 0) { - return false; - } - - // - We are not using UnknownFieldSet (part of the non-lite library). - if (UseUnknownFieldSet(descriptor->file(), options)) { - return false; - } - // - We have has_bits for fields. This avoids a check on every field we set // when are present (the common case). if (!HasFieldPresence(descriptor->file())) { @@ -482,16 +475,6 @@ bool TableDrivenEnabled(const Descriptor* descriptor, const Options& options) { max_field_number = field->number(); } - // - There are no map fields. - if (field->is_map()) { - return false; - } - - // - There are no oneof fields. - if (field->containing_oneof()) { - return false; - } - // - There are no weak fields. if (field->options().weak()) { return false; @@ -503,8 +486,10 @@ bool TableDrivenEnabled(const Descriptor* descriptor, const Options& options) { return false; } - // - Field numbers are relatively dense within the actual number of fields - if (max_field_number * table_sparseness >= descriptor->field_count()) { + // - Field numbers are relatively dense within the actual number of fields. + // We check for strictly greater than in the case where there are no fields + // (only extensions) so max_field_number == descriptor->field_count() == 0. + if (max_field_number * table_sparseness > descriptor->field_count()) { return false; } @@ -516,6 +501,31 @@ bool TableDrivenEnabled(const Descriptor* descriptor, const Options& options) { return true; } +void SetUnknkownFieldsVariable(const Descriptor* descriptor, + const Options& options, + std::map<string, string>* variables) { + if (UseUnknownFieldSet(descriptor->file(), options)) { + (*variables)["unknown_fields_type"] = "::google::protobuf::UnknownFieldSet"; + } else { + (*variables)["unknown_fields_type"] = "::std::string"; + } + if (AlwaysPreserveUnknownFields(descriptor)) { + (*variables)["have_unknown_fields"] = + "_internal_metadata_.have_unknown_fields()"; + (*variables)["unknown_fields"] = "_internal_metadata_.unknown_fields()"; + } else { + (*variables)["have_unknown_fields"] = + "(_internal_metadata_.have_unknown_fields() && " + " ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())"; + (*variables)["unknown_fields"] = + "(::google::protobuf::internal::GetProto3PreserveUnknownsDefault()" + " ? _internal_metadata_.unknown_fields()" + " : _internal_metadata_.default_instance())"; + } + (*variables)["mutable_unknown_fields"] = + "_internal_metadata_.mutable_unknown_fields()"; +} + } // anonymous namespace // =================================================================== @@ -592,7 +602,7 @@ MessageGenerator::MessageGenerator(const Descriptor* descriptor, use_dependent_base_ = true; } - table_driven_ = TableDrivenEnabled(descriptor_, options_); + table_driven_ = TableDrivenParsingEnabled(descriptor_, options_); } MessageGenerator::~MessageGenerator() {} @@ -703,24 +713,29 @@ GenerateFieldAccessorDeclarations(io::Printer* printer) { } if (field->is_repeated()) { - printer->Print(vars, "$deprecated_attr$int $name$_size() const;\n"); + printer->Print(vars, "$deprecated_attr$int ${$$name$_size$}$() const;\n"); + printer->Annotate("{", "}", field); } else if (HasHasMethod(field)) { - printer->Print(vars, "$deprecated_attr$bool has_$name$() const;\n"); + printer->Print(vars, "$deprecated_attr$bool ${$has_$name$$}$() const;\n"); + printer->Annotate("{", "}", field); } else if (HasPrivateHasMethod(field)) { printer->Print(vars, - "private:\n" - "bool has_$name$() const;\n" - "public:\n"); + "private:\n" + "bool ${$has_$name$$}$() const;\n" + "public:\n"); + printer->Annotate("{", "}", field); } if (!dependent_field) { // If this field is dependent, then its clear_() method is in the // depenent base class. (See also GenerateDependentAccessorDeclarations.) - printer->Print(vars, "$deprecated_attr$void clear_$name$();\n"); + printer->Print(vars, "$deprecated_attr$void ${$clear_$name$$}$();\n"); + printer->Annotate("{", "}", field); } printer->Print(vars, "$deprecated_attr$static const int $constant_name$ = " "$number$;\n"); + printer->Annotate("constant_name", field); // Generate type-specific accessor declarations. field_generators_.get(field).GenerateAccessorDeclarations(printer); @@ -1074,32 +1089,39 @@ GenerateClassDefinition(io::Printer* printer) { printer->Print(" public:\n"); printer->Indent(); - printer->Print(vars, - "$classname$();\n" - "virtual ~$classname$();\n" - "\n" - "$classname$(const $classname$& from);\n" - "\n" - "inline $classname$& operator=(const $classname$& from) {\n" - " CopyFrom(from);\n" - " return *this;\n" - "}\n" - "\n"); + printer->Print( + vars, + "$classname$();\n" + "virtual ~$classname$();\n" + "\n" + "$classname$(const $classname$& from);\n" + "\n" + "inline $classname$& operator=(const $classname$& from) {\n" + " CopyFrom(from);\n" + " return *this;\n" + "}\n"); + + if (options_.table_driven_serialization) { + printer->Print( + "private:\n" + "const void* InternalGetTable() const;\n" + "public:\n" + "\n"); + } // Generate move constructor and move assignment operator for types other than // Any. - #ifdef PROTO_EXPERIMENTAL_ENABLE_MOVE if (!IsAnyMessage(descriptor_)) { printer->Print(vars, "#if LANG_CXX11\n" - "$classname$($classname$&& from)\n" + "$classname$($classname$&& from) noexcept\n" " : $classname$() {\n" " *this = ::std::move(from);\n" "}\n" "\n" - "inline $classname$& operator=($classname$&& from) {\n" + "inline $classname$& operator=($classname$&& from) noexcept {\n" " if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) {\n" - " InternalSwap(&from);\n" + " if (this != &from) InternalSwap(&from);\n" " } else {\n" " CopyFrom(from);\n" " }\n" @@ -1107,22 +1129,17 @@ GenerateClassDefinition(io::Printer* printer) { "}\n" "#endif\n"); } - #endif - if (PreserveUnknownFields(descriptor_)) { - string type = UseUnknownFieldSet(descriptor_->file(), options_) - ? "::google::protobuf::UnknownFieldSet" - : "::std::string"; - printer->Print( - "inline const $type$& unknown_fields() const {\n" - " return _internal_metadata_.unknown_fields();\n" - "}\n" - "\n" - "inline $type$* mutable_unknown_fields() {\n" - " return _internal_metadata_.mutable_unknown_fields();\n" - "}\n" - "\n", - "type", type ); + SetUnknkownFieldsVariable(descriptor_, options_, &vars); + if (PublicUnknownFieldsAccessors(descriptor_)) { + printer->Print(vars, + "inline const $unknown_fields_type$& unknown_fields() const {\n" + " return $unknown_fields$;\n" + "}\n" + "inline $unknown_fields_type$* mutable_unknown_fields() {\n" + " return $mutable_unknown_fields$;\n" + "}\n" + "\n"); } // N.B.: We exclude GetArena() when arena support is disabled, falling back on @@ -1190,7 +1207,6 @@ GenerateClassDefinition(io::Printer* printer) { " $message_index$;\n" "\n"); - if (SupportsArenas(descriptor_)) { printer->Print(vars, "void UnsafeArenaSwap($classname$* other);\n"); @@ -1214,6 +1230,9 @@ GenerateClassDefinition(io::Printer* printer) { printer->Print(vars, "void Swap($classname$* other);\n" + "friend void swap($classname$& a, $classname$& b) {\n" + " a.Swap(&b);\n" + "}\n" "\n" "// implements Message ----------------------------------------------\n" "\n" @@ -1250,9 +1269,14 @@ GenerateClassDefinition(io::Printer* printer) { "\n" "size_t ByteSizeLong() const PROTOBUF_FINAL;\n" "bool MergePartialFromCodedStream(\n" - " ::google::protobuf::io::CodedInputStream* input)$merge_partial_final$;\n" - "void SerializeWithCachedSizes(\n" - " ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL;\n"); + " ::google::protobuf::io::CodedInputStream* input)$merge_partial_final$;\n"); + if (!options_.table_driven_serialization || + descriptor_->options().message_set_wire_format()) { + printer->Print( + "void SerializeWithCachedSizes(\n" + " ::google::protobuf::io::CodedOutputStream* output) const " + "PROTOBUF_FINAL;\n"); + } // DiscardUnknownFields() is implemented in message.cc using reflections. We // need to implement this function in generated code for messages. if (!UseUnknownFieldSet(descriptor_->file(), options_)) { @@ -1278,6 +1302,9 @@ GenerateClassDefinition(io::Printer* printer) { "final", use_final); if (SupportsArenas(descriptor_)) { printer->Print( + // TODO(gerbens) Make this private! Currently people are deriving from + // protos to give access to this constructor, breaking the invariants + // we rely on. "protected:\n" "explicit $classname$(::google::protobuf::Arena* arena);\n" "private:\n" @@ -1443,7 +1470,7 @@ GenerateClassDefinition(io::Printer* printer) { if (SupportsArenas(descriptor_)) { printer->Print( - "friend class ::google::protobuf::Arena;\n" + "template <typename T> friend class ::google::protobuf::Arena::InternalHelper;\n" "typedef void InternalArenaConstructable_;\n" "typedef void DestructorSkippable_;\n"); } @@ -1639,9 +1666,44 @@ bool MessageGenerator::GenerateParseTable(io::Printer* printer, size_t offset, " $classname$, _has_bits_),\n"); } + if (descriptor_->oneof_decl_count() > 0) { + printer->Print(vars, + "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(\n" + " $classname$, _oneof_case_),\n"); + } else { + printer->Print("-1, // no _oneof_case_\n"); + } + + if (descriptor_->extension_range_count() > 0) { + printer->Print(vars, + "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, " + "_extensions_),\n"); + } else { + printer->Print("-1, // no _extensions_\n"); + } + + // TODO(ckennelly): Consolidate this with the calculation for + // AuxillaryParseTableField. + std::vector<string> package_parts; + + const Descriptor* outer = descriptor_; + while (outer->containing_type() != NULL) { + outer = outer->containing_type(); + } + + package_parts = Split( + outer->full_name(), ".", true); + // outer->full_name() contains the class itself. Remove it as it is + // used in the name of the default instance variable. + GOOGLE_DCHECK_NE(package_parts.size(), 0); + package_parts.back().clear(); + + vars["ns"] = Join(package_parts, "::"); + printer->Print(vars, "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(\n" - " $classname$, _internal_metadata_),\n"); + " $classname$, _internal_metadata_),\n" + "&::$ns$_$classname$_default_instance_,\n"); if (UseUnknownFieldSet(descriptor_->file(), options_)) { printer->Print(vars, "true,\n"); @@ -1670,6 +1732,239 @@ void MessageGenerator::GenerateSchema(io::Printer* printer, int offset, "{ $offset$, $has_bits_offsets$, sizeof($classname$)},\n"); } +namespace { + +// TODO(gerbens) remove this after the next sync with GitHub code base. +// Then the opensource testing has gained the functionality to compile +// the CalcFieldNum given the symbols defined in generated-message-util. +#ifdef OPENSOURCE_PROTOBUF_CPP_BOOTSTRAP +// We need a clean version of CalcFieldNum that doesn't use new functionality +// in the runtime, because this functionality is not yet in the opensource +// runtime + +uint32 CalculateType(uint32 type, uint32 type_class) { + return (type - 1) + type_class * 20; +} + +uint32 CalcFieldNum(const FieldDescriptor* field, const Options& options) { + bool is_a_map = IsMapEntryMessage(field->containing_type()); + int type = field->type(); + if (field->containing_oneof()) { + return CalculateType(type, 4); + } + if (field->is_packed()) { + return CalculateType(type, 3); + } else if (field->is_repeated()) { + return CalculateType(type, 2); + } else if (!HasFieldPresence(field->file()) && + field->containing_oneof() == NULL && !is_a_map) { + return CalculateType(type, 1); + } else { + return CalculateType(type, 0); + } +} + +#else +// We need to calculate for each field what function the table driven code +// should use to serialize it. This returns the index in a lookup table. +uint32 CalcFieldNum(const FieldDescriptor* field, const Options& options) { + bool is_a_map = IsMapEntryMessage(field->containing_type()); + int type = field->type(); + if (field->containing_oneof()) { + return internal::FieldMetadata::CalculateType( + type, internal::FieldMetadata::kOneOf); + } + if (field->is_packed()) { + return internal::FieldMetadata::CalculateType( + type, internal::FieldMetadata::kPacked); + } else if (field->is_repeated()) { + return internal::FieldMetadata::CalculateType( + type, internal::FieldMetadata::kRepeated); + } else if (!HasFieldPresence(field->file()) && + field->containing_oneof() == NULL && !is_a_map) { + return internal::FieldMetadata::CalculateType( + type, internal::FieldMetadata::kNoPresence); + } else { + return internal::FieldMetadata::CalculateType( + type, internal::FieldMetadata::kPresence); + } +} +#endif + +int FindMessageIndexInFile(const Descriptor* descriptor) { + std::vector<const Descriptor*> flatten = + FlattenMessagesInFile(descriptor->file()); + return std::find(flatten.begin(), flatten.end(), descriptor) - + flatten.begin(); +} + +} // namespace + +int MessageGenerator::GenerateFieldMetadata(io::Printer* printer) { + if (!options_.table_driven_serialization) { + return 0; + } + + std::vector<const FieldDescriptor*> sorted = SortFieldsByNumber(descriptor_); + if (IsMapEntryMessage(descriptor_)) { + for (int i = 0; i < 2; i++) { + const FieldDescriptor* field = sorted[i]; + uint32 tag = internal::WireFormatLite::MakeTag( + field->number(), WireFormat::WireTypeForFieldType(field->type())); + + std::map<string, string> vars; + vars["classname"] = classname_; + vars["parent_classname"] = + ClassName(descriptor_->containing_type(), false); + vars["field_name"] = FieldName(field); + vars["tag"] = SimpleItoa(tag); + vars["hasbit"] = SimpleItoa(i); + vars["type"] = SimpleItoa(CalcFieldNum(field, options_)); + vars["ptr"] = "NULL"; + if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { + GOOGLE_CHECK(!IsMapEntryMessage(field->message_type())); + { + vars["ptr"] = + QualifiedFileLevelSymbol( + field->message_type()->file()->package(), + FileLevelNamespace(field->message_type()->file()->name())) + + "::TableStruct::serialization_table + " + + SimpleItoa(FindMessageIndexInFile(field->message_type())); + } + } + vars["extra"] = HasDescriptorMethods(descriptor_->file(), options_) + ? "::SuperType" + : ""; + printer->Print(vars, + "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(" + "::google::protobuf::internal::MapEntryHelper<$parent_classname$::$" + "classname$$extra$>, $field_name$_), $tag$," + "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(" + "::google::protobuf::internal::MapEntryHelper<$parent_classname$::$" + "classname$$extra$>, _has_bits_) * 8 + $hasbit$, $type$, " + "$ptr$},\n"); + } + return 2; + } + printer->Print( + "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, " + "_cached_size_), 0, 0, 0, NULL},\n", + "classname", classname_); + std::vector<const Descriptor::ExtensionRange*> sorted_extensions; + for (int i = 0; i < descriptor_->extension_range_count(); ++i) { + sorted_extensions.push_back(descriptor_->extension_range(i)); + } + std::sort(sorted_extensions.begin(), sorted_extensions.end(), + ExtensionRangeSorter()); + for (int i = 0, extension_idx = 0; /* no range */; i++) { + for (; extension_idx < sorted_extensions.size() && + (i == sorted.size() || + sorted_extensions[extension_idx]->start < sorted[i]->number()); + extension_idx++) { + const Descriptor::ExtensionRange* range = + sorted_extensions[extension_idx]; + printer->Print( + "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, " + "_extensions_), $start$, $end$, " + "::google::protobuf::internal::FieldMetadata::kSpecial, " + "reinterpret_cast<const " + "void*>(::google::protobuf::internal::ExtensionSerializer)},\n", + "classname", classname_, "start", SimpleItoa(range->start), "end", + SimpleItoa(range->end)); + } + if (i == sorted.size()) break; + const FieldDescriptor* field = sorted[i]; + + uint32 tag = internal::WireFormatLite::MakeTag( + field->number(), WireFormat::WireTypeForFieldType(field->type())); + if (field->is_packed()) { + tag = internal::WireFormatLite::MakeTag( + field->number(), WireFormatLite::WIRETYPE_LENGTH_DELIMITED); + } + + string classfieldname = FieldName(field); + if (field->containing_oneof()) { + classfieldname = field->containing_oneof()->name(); + } + std::map<string, string> vars; + vars["classname"] = classname_; + vars["field_name"] = classfieldname; + vars["tag"] = SimpleItoa(tag); + vars["ptr"] = "NULL"; + if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { + if (IsMapEntryMessage(field->message_type())) { + vars["idx"] = SimpleItoa(FindMessageIndexInFile(field->message_type())); + vars["fieldclassname"] = ClassName(field->message_type(), false); + printer->Print(vars, + "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($" + "classname$, $field_name$_), $tag$, $idx$, " + "::google::protobuf::internal::FieldMetadata::kSpecial, " + "reinterpret_cast<const void*>(static_cast< " + "::google::protobuf::internal::SpecialSerializer>(" + "::google::protobuf::internal::MapFieldSerializer< " + "::google::protobuf::internal::MapEntryToMapField<$classname$::$" + "fieldclassname$>::MapFieldType, " + "TableStruct::serialization_table>))},\n"); + continue; + } else { + vars["ptr"] = + QualifiedFileLevelSymbol( + field->message_type()->file()->package(), + FileLevelNamespace(field->message_type()->file()->name())) + + "::TableStruct::serialization_table + " + + SimpleItoa(FindMessageIndexInFile(field->message_type())); + } + } + vars["type"] = SimpleItoa(CalcFieldNum(field, options_)); + + + if (field->options().weak()) { + // TODO(gerbens) merge weak fields into ranges + printer->Print(vars, + "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($" + "classname$, _weak_field_map_), $tag$, $tag$, " + "::google::protobuf::internal::FieldMetadata::kSpecial, " + "reinterpret_cast<const " + "void*>(::google::protobuf::internal::WeakFieldSerializer)},\n"); + } else if (field->containing_oneof()) { + vars["oneofoffset"] = + SimpleItoa(sizeof(uint32) * field->containing_oneof()->index()); + printer->Print(vars, + "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($" + "classname$, $field_name$_), $tag$, " + "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($" + "classname$, _oneof_case_) + $oneofoffset$, " + "$type$, $ptr$},\n"); + } else if (HasFieldPresence(descriptor_->file()) && + has_bit_indices_[field->index()] != -1) { + vars["hasbitsoffset"] = SimpleItoa(has_bit_indices_[field->index()]); + printer->Print(vars, + "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($" + "classname$, $field_name$_), $tag$, " + "GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($" + "classname$, _has_bits_) * 8 + $hasbitsoffset$, $type$, " + "$ptr$},\n"); + } else { + printer->Print(vars, + "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($" + "classname$, $field_name$_), $tag$, ~0u, $type$, " + "$ptr$},\n"); + } + } + int num_field_metadata = 1 + sorted.size() + sorted_extensions.size(); + num_field_metadata++; + string serializer = UseUnknownFieldSet(descriptor_->file(), options_) + ? "::google::protobuf::internal::UnknownFieldSetSerializer" + : "::google::protobuf::internal::UnknownFieldSerializerLite"; + printer->Print( + "{GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET($classname$, " + "_internal_metadata_), 0, ~0u, " + "::google::protobuf::internal::FieldMetadata::kSpecial, reinterpret_cast<const " + "void*>($serializer$)},\n", + "classname", classname_, "serializer", serializer); + return num_field_metadata; +} + void MessageGenerator:: GenerateDefaultInstanceAllocator(io::Printer* printer) { // Construct the default instances of all fields, as they will be used @@ -1732,25 +2027,6 @@ GenerateDefaultInstanceInitializer(io::Printer* printer) { } void MessageGenerator:: -GenerateShutdownCode(io::Printer* printer) { - if (IsMapEntryMessage(descriptor_)) return; - - printer->Print("_$classname$_default_instance_.Shutdown();\n", "classname", - classname_); - - if (HasDescriptorMethods(descriptor_->file(), options_)) { - printer->Print("delete file_level_metadata[$index$].reflection;\n", "index", - SimpleItoa(index_in_file_messages_)); - } - - // Handle default instances of fields. - for (int i = 0; i < descriptor_->field_count(); i++) { - field_generators_.get(descriptor_->field(i)) - .GenerateShutdownCode(printer); - } -} - -void MessageGenerator:: GenerateClassMethods(io::Printer* printer) { if (IsMapEntryMessage(descriptor_)) { if (HasDescriptorMethods(descriptor_->file(), options_)) { @@ -1854,6 +2130,15 @@ GenerateClassMethods(io::Printer* printer) { GenerateSwap(printer); printer->Print("\n"); + if (options_.table_driven_serialization) { + printer->Print( + "const void* $classname$::InternalGetTable() const {\n" + " return $file_namespace$::TableStruct::serialization_table + $index$;\n" + "}\n" + "\n", + "classname", classname_, "index", SimpleItoa(index_in_file_messages_), + "file_namespace", FileLevelNamespace(descriptor_->file()->name())); + } if (HasDescriptorMethods(descriptor_->file(), options_)) { printer->Print( "::google::protobuf::Metadata $classname$::GetMetadata() const {\n" @@ -1926,13 +2211,25 @@ size_t MessageGenerator::GenerateParseOffsets(io::Printer* printer) { processing_type |= static_cast<unsigned>( field->is_repeated() ? internal::kRepeatedMask : 0); + processing_type |= static_cast<unsigned>( + field->containing_oneof() ? internal::kOneofMask : 0); + + if (field->is_map()) { + processing_type = internal::TYPE_MAP; + } + const unsigned char tag_size = WireFormat::TagSize(field->number(), field->type()); std::map<string, string> vars; vars["classname"] = classname_; - vars["name"] = FieldName(field); - vars["has"] = SimpleItoa(has_bit_indices_[field->index()]); + if (field->containing_oneof() != NULL) { + vars["name"] = field->containing_oneof()->name(); + vars["presence"] = SimpleItoa(field->containing_oneof()->index()); + } else { + vars["name"] = FieldName(field); + vars["presence"] = SimpleItoa(has_bit_indices_[field->index()]); + } vars["nwtype"] = SimpleItoa(normal_wiretype); vars["pwtype"] = SimpleItoa(packed_wiretype); vars["ptype"] = SimpleItoa(processing_type); @@ -1942,7 +2239,7 @@ size_t MessageGenerator::GenerateParseOffsets(io::Printer* printer) { "{\n" " GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(\n" " $classname$, $name$_),\n" - " static_cast< ::google::protobuf::uint32>($has$),\n" + " static_cast< ::google::protobuf::uint32>($presence$),\n" " $nwtype$, $pwtype$, $ptype$, $tag_size$\n" "},\n"); } @@ -1977,7 +2274,7 @@ size_t MessageGenerator::GenerateParseAuxTable(io::Printer* printer) { printer->Print( vars, "{::google::protobuf::internal::AuxillaryParseTableField::enum_aux{" - "$type$_IsValid, \"$type$\" }},\n"); + "$type$_IsValid}},\n"); last_field_number++; break; case FieldDescriptor::CPPTYPE_MESSAGE: { @@ -1995,7 +2292,17 @@ size_t MessageGenerator::GenerateParseAuxTable(io::Printer* printer) { GOOGLE_DCHECK_NE(package_parts.size(), 0); package_parts.back().clear(); - vars["classname"] = ClassName(field->message_type(), false); + if (field->is_map()) { + vars["classname"] = ClassName(field->containing_type(), false) + + "::" + ClassName(field->message_type(), false); + printer->Print(vars, + "{::google::protobuf::internal::AuxillaryParseTableField::map_" + "aux{&::google::protobuf::internal::ParseMap<$classname$>}},\n"); + last_field_number++; + break; + } else { + vars["classname"] = ClassName(field->message_type(), false); + } vars["ns"] = Join(package_parts, "::"); vars["type"] = FieldMessageTypeName(field); vars["file_namespace"] = FileLevelNamespace(outer->file()->name()); @@ -2005,7 +2312,7 @@ size_t MessageGenerator::GenerateParseAuxTable(io::Printer* printer) { " &::$ns$_$classname$_default_instance_,\n"); bool dont_emit_table = - !TableDrivenEnabled(field->message_type(), options_); + !TableDrivenParsingEnabled(field->message_type(), options_); if (dont_emit_table) { printer->Print(" NULL,\n"); @@ -2034,16 +2341,10 @@ size_t MessageGenerator::GenerateParseAuxTable(io::Printer* printer) { break; } vars["full_name"] = field->full_name(); - vars["strict"] = - field->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 - ? "true" : "false"; - vars["type"] = field->full_name(); printer->Print(vars, "{::google::protobuf::internal::AuxillaryParseTableField::string_aux{\n" " $default$,\n" - " \"$full_name$\",\n" - " $strict$,\n" - " \"$type$\"\n" + " \"$full_name$\"\n" "}},\n"); last_field_number++; break; @@ -2103,8 +2404,7 @@ std::pair<size_t, size_t> MessageGenerator::GenerateOffsets( const FieldDescriptor* field = descriptor_->field(i); if (field->containing_oneof() || field->options().weak()) { printer->Print( - "GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(" - "(&_$classname$_default_instance_), $name$_),\n", + "offsetof($classname$DefaultTypeInternal, $name$_),\n", "classname", classname_, "name", FieldName(field)); } else { printer->Print( @@ -2178,6 +2478,7 @@ GenerateSharedDestructorCode(io::Printer* printer) { // Do nothing when the message is allocated in an arena. printer->Print( "::google::protobuf::Arena* arena = GetArenaNoVirtual();\n" + "GOOGLE_DCHECK(arena == NULL);\n" "if (arena != NULL) {\n" " return;\n" "}\n" @@ -2384,8 +2685,7 @@ GenerateStructors(io::Printer* printer) { initializer_with_arena += ", _weak_field_map_(arena)"; } - string initializer_null; - initializer_null = ", _internal_metadata_(NULL)"; + string initializer_null = superclass + "(), _internal_metadata_(NULL)"; if (IsAnyMessage(descriptor_)) { initializer_null += ", _any_metadata_(&type_url_, &value_)"; } @@ -2395,26 +2695,22 @@ GenerateStructors(io::Printer* printer) { printer->Print( "$classname$::$classname$()\n" - " : $superclass$()$initializer$ {\n" + " : $initializer$ {\n" " if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) {\n" " $file_namespace$::InitDefaults();\n" " }\n" " SharedCtor();\n" " // @@protoc_insertion_point(constructor:$full_name$)\n" "}\n", - "classname", classname_, "superclass", superclass, "full_name", - descriptor_->full_name(), "initializer", initializer_null, - "file_namespace", FileLevelNamespace(descriptor_->file()->name())); + "classname", classname_, "full_name", descriptor_->full_name(), + "initializer", initializer_null, "file_namespace", + FileLevelNamespace(descriptor_->file()->name())); if (SupportsArenas(descriptor_)) { printer->Print( "$classname$::$classname$(::google::protobuf::Arena* arena)\n" " : $initializer$ {\n" - // When arenas are used it's safe to assume we have finished - // static init time (protos with arenas are unsafe during static init) - "#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n" " $file_namespace$::InitDefaults();\n" - "#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER\n" " SharedCtor();\n" " RegisterArenaDtor(arena);\n" " // @@protoc_insertion_point(arena_constructor:$full_name$)\n" @@ -2601,7 +2897,6 @@ GenerateStructors(io::Printer* printer) { "}\n", "classname", classname_); } - } // Return the number of bits set in n, a non-negative integer. @@ -2614,6 +2909,22 @@ static int popcnt(uint32 n) { return result; } +bool MessageGenerator::MaybeGenerateOptionalFieldCondition( + io::Printer* printer, const FieldDescriptor* field, + int expected_has_bits_index) { + int has_bit_index = has_bit_indices_[field->index()]; + if (!field->options().weak() && + expected_has_bits_index == has_bit_index / 32) { + const string mask = + StrCat(strings::Hex(1u << (has_bit_index % 32), strings::ZERO_PAD_8)); + printer->Print( + "if (cached_has_bits & 0x$mask$u) {\n", + "mask", mask); + return true; + } + return false; +} + void MessageGenerator:: GenerateClear(io::Printer* printer) { printer->Print( @@ -2622,6 +2933,15 @@ GenerateClear(io::Printer* printer) { "classname", classname_, "full_name", descriptor_->full_name()); printer->Indent(); + printer->Print( + // TODO(jwb): It would be better to avoid emitting this if it is not used, + // rather than emitting a workaround for the resulting warning. + "::google::protobuf::uint32 cached_has_bits = 0;\n" + "// Prevent compiler warnings about cached_has_bits being unused\n" + "(void) cached_has_bits;\n\n"); + + int cached_has_bit_index = -1; + // Step 1: Extensions if (descriptor_->extension_range_count() > 0) { printer->Print("_extensions_.Clear();\n"); @@ -2730,9 +3050,14 @@ GenerateClear(io::Printer* printer) { GOOGLE_DCHECK_LE(2, count); GOOGLE_DCHECK_GE(8, count); + if (cached_has_bit_index != last_chunk / 4) { + cached_has_bit_index = last_chunk / 4; + printer->Print( + "cached_has_bits = _has_bits_[$idx$];\n", + "idx", SimpleItoa(cached_has_bit_index)); + } printer->Print( - "if (_has_bits_[$index$ / 32] & $mask$u) {\n", - "index", SimpleItoa(last_chunk * 8), + "if (cached_has_bits & $mask$u) {\n", "mask", SimpleItoa(last_chunk_mask)); printer->Indent(); } @@ -2778,7 +3103,12 @@ GenerateClear(io::Printer* printer) { if (should_check_bit && // If no field presence, then always clear strings/messages as well. HasFieldPresence(descriptor_->file())) { - printer->Print("if (has_$name$()) {\n", "name", fieldname); + if (!MaybeGenerateOptionalFieldCondition(printer, field, + cached_has_bit_index)) { + printer->Print( + "if (has_$name$()) {\n", + "name", fieldname); + } printer->Indent(); have_enclosing_if = true; } @@ -2814,9 +3144,7 @@ GenerateClear(io::Printer* printer) { printer->Print("_has_bits_.Clear();\n"); } - if (PreserveUnknownFields(descriptor_)) { - printer->Print("_internal_metadata_.Clear();\n"); - } + printer->Print("_internal_metadata_.Clear();\n"); printer->Outdent(); printer->Print("}\n"); @@ -2920,6 +3248,7 @@ GenerateSwap(io::Printer* printer) { printer->Print("void $classname$::InternalSwap($classname$* other) {\n", "classname", classname_); printer->Indent(); + printer->Print("using std::swap;\n"); if (HasGeneratedMethods(descriptor_->file(), options_)) { for (int i = 0; i < optimized_order_.size(); i++) { @@ -2931,24 +3260,22 @@ GenerateSwap(io::Printer* printer) { for (int i = 0; i < descriptor_->oneof_decl_count(); i++) { printer->Print( - "std::swap($oneof_name$_, other->$oneof_name$_);\n" - "std::swap(_oneof_case_[$i$], other->_oneof_case_[$i$]);\n", + "swap($oneof_name$_, other->$oneof_name$_);\n" + "swap(_oneof_case_[$i$], other->_oneof_case_[$i$]);\n", "oneof_name", descriptor_->oneof_decl(i)->name(), "i", SimpleItoa(i)); } if (HasFieldPresence(descriptor_->file())) { for (int i = 0; i < HasBitsSize() / 4; ++i) { - printer->Print("std::swap(_has_bits_[$i$], other->_has_bits_[$i$]);\n", + printer->Print("swap(_has_bits_[$i$], other->_has_bits_[$i$]);\n", "i", SimpleItoa(i)); } } - if (PreserveUnknownFields(descriptor_)) { - printer->Print("_internal_metadata_.Swap(&other->_internal_metadata_);\n"); - } + printer->Print("_internal_metadata_.Swap(&other->_internal_metadata_);\n"); - printer->Print("std::swap(_cached_size_, other->_cached_size_);\n"); + printer->Print("swap(_cached_size_, other->_cached_size_);\n"); if (descriptor_->extension_range_count() > 0) { printer->Print("_extensions_.Swap(&other->_extensions_);\n"); } @@ -3251,21 +3578,16 @@ GenerateCopyFrom(io::Printer* printer) { void MessageGenerator:: GenerateMergeFromCodedStream(io::Printer* printer) { + std::map<string, string> vars; + SetUnknkownFieldsVariable(descriptor_, options_, &vars); if (descriptor_->options().message_set_wire_format()) { // Special-case MessageSet. - printer->Print( + vars["classname"] = classname_; + printer->Print(vars, "bool $classname$::MergePartialFromCodedStream(\n" - " ::google::protobuf::io::CodedInputStream* input) {\n", - "classname", classname_); - - printer->Print( - " return _extensions_.ParseMessageSet(input, " - "internal_default_instance(),\n" - " mutable_unknown_fields());\n", - // Vars. - "classname", classname_); - - printer->Print( + " ::google::protobuf::io::CodedInputStream* input) {\n" + " return _extensions_.ParseMessageSet(input,\n" + " internal_default_instance(), $mutable_unknown_fields$);\n" "}\n"); return; } @@ -3281,14 +3603,18 @@ GenerateMergeFromCodedStream(io::Printer* printer) { if (table_driven_) { printer->Indent(); + const string lite = UseUnknownFieldSet(descriptor_->file(), options_) ? + "" : "Lite"; + printer->Print( - "return ::google::protobuf::internal::MergePartialFromCodedStream(\n" + "return ::google::protobuf::internal::MergePartialFromCodedStream$lite$(\n" " this,\n" " $file_namespace$::TableStruct::schema[\n" " $classname$::kIndexInFileMessages],\n" " input);\n", "classname", classname_, - "file_namespace", FileLevelNamespace(descriptor_->file()->name())); + "file_namespace", FileLevelNamespace(descriptor_->file()->name()), + "lite", lite); printer->Outdent(); @@ -3300,8 +3626,7 @@ GenerateMergeFromCodedStream(io::Printer* printer) { "#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure\n" " ::google::protobuf::uint32 tag;\n"); - if (PreserveUnknownFields(descriptor_) && - !UseUnknownFieldSet(descriptor_->file(), options_)) { + if (!UseUnknownFieldSet(descriptor_->file(), options_)) { // Use LazyStringOutputString to avoid initializing unknown fields string // unless it is actually needed. For the same reason, disable eager refresh // on the CodedOutputStream. @@ -3354,13 +3679,12 @@ GenerateMergeFromCodedStream(io::Printer* printer) { } printer->Print("::std::pair< ::google::protobuf::uint32, bool> p = " - "input->ReadTagWithCutoff$lasttag$($max$u);\n" + "input->ReadTagWithCutoffNoLastTag($max$u);\n" "tag = p.first;\n" "if (!p.second) goto handle_unusual;\n", "max", SimpleItoa(maxtag <= kCutoff0 ? kCutoff0 : (maxtag <= kCutoff1 ? kCutoff1 : - maxtag)), - "lasttag", !capture_last_tag ? "NoLastTag" : ""); + maxtag))); if (descriptor_->field_count() > 0) { // We don't even want to print the switch() if we have no fields because @@ -3395,9 +3719,11 @@ GenerateMergeFromCodedStream(io::Printer* printer) { const FieldGenerator& field_generator = field_generators_.get(field); // Emit code to parse the common, expected case. - printer->Print("if (static_cast< ::google::protobuf::uint8>(tag) ==\n" - " static_cast< ::google::protobuf::uint8>($commontag$u)) {\n", - "commontag", SimpleItoa(WireFormat::MakeTag(field))); + printer->Print( + "if (static_cast< ::google::protobuf::uint8>(tag) ==\n" + " static_cast< ::google::protobuf::uint8>($truncated$u /* $full$ & 0xFF */)) {\n", + "truncated", SimpleItoa(WireFormat::MakeTag(field) & 0xFF), + "full", SimpleItoa(WireFormat::MakeTag(field))); printer->Indent(); if (field->is_packed()) { @@ -3411,22 +3737,30 @@ GenerateMergeFromCodedStream(io::Printer* printer) { if (field->is_packed()) { internal::WireFormatLite::WireType wiretype = WireFormat::WireTypeForFieldType(field->type()); - printer->Print("} else if (static_cast< ::google::protobuf::uint8>(tag) ==\n" - " static_cast< ::google::protobuf::uint8>($uncommontag$u)) {\n", - "uncommontag", SimpleItoa( - internal::WireFormatLite::MakeTag( - field->number(), wiretype))); + const uint32 tag = internal::WireFormatLite::MakeTag( + field->number(), wiretype); + printer->Print( + "} else if (\n" + " static_cast< ::google::protobuf::uint8>(tag) ==\n" + " static_cast< ::google::protobuf::uint8>($truncated$u /* $full$ & 0xFF */)) {\n", + "truncated", SimpleItoa(tag & 0xFF), + "full", SimpleItoa(tag)); + printer->Indent(); field_generator.GenerateMergeFromCodedStream(printer); printer->Outdent(); } else if (field->is_packable() && !field->is_packed()) { internal::WireFormatLite::WireType wiretype = internal::WireFormatLite::WIRETYPE_LENGTH_DELIMITED; - printer->Print("} else if (static_cast< ::google::protobuf::uint8>(tag) ==\n" - " static_cast< ::google::protobuf::uint8>($uncommontag$u)) {\n", - "uncommontag", SimpleItoa( - internal::WireFormatLite::MakeTag( - field->number(), wiretype))); + const uint32 tag = internal::WireFormatLite::MakeTag( + field->number(), wiretype); + + printer->Print( + "} else if (\n" + " static_cast< ::google::protobuf::uint8>(tag) ==\n" + " static_cast< ::google::protobuf::uint8>($truncated$u /* $full$ & 0xFF */)) {\n", + "truncated", SimpleItoa(tag & 0xFF), + "full", SimpleItoa(tag)); printer->Indent(); field_generator.GenerateMergeFromCodedStreamWithPacking(printer); printer->Outdent(); @@ -3452,12 +3786,20 @@ GenerateMergeFromCodedStream(io::Printer* printer) { printer->Print("handle_unusual:\n"); printer->Indent(); // If tag is 0 or an end-group tag then this must be the end of the message. - printer->Print( - "if (tag == 0 ||\n" - " ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==\n" - " ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {\n" - " goto success;\n" - "}\n"); + if (capture_last_tag) { + printer->Print( + "if (tag == 0 ||\n" + " ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) ==\n" + " ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) {\n" + " input->SetLastTag(tag);\n" + " goto success;\n" + "}\n"); + } else { + printer->Print( + "if (tag == 0) {\n" + " goto success;\n" + "}\n"); + } // Handle extension ranges. if (descriptor_->extension_range_count() > 0) { @@ -3485,23 +3827,16 @@ GenerateMergeFromCodedStream(io::Printer* printer) { } } printer->Print(") {\n"); - if (PreserveUnknownFields(descriptor_)) { - if (UseUnknownFieldSet(descriptor_->file(), options_)) { - printer->Print( - " DO_(_extensions_.ParseField(tag, input, " - "internal_default_instance(),\n" - " mutable_unknown_fields()));\n"); - } else { - printer->Print( - " DO_(_extensions_.ParseField(tag, input, " - "internal_default_instance(),\n" - " &unknown_fields_stream));\n"); - } + if (UseUnknownFieldSet(descriptor_->file(), options_)) { + printer->Print(vars, + " DO_(_extensions_.ParseField(tag, input,\n" + " internal_default_instance(),\n" + " $mutable_unknown_fields$));\n"); } else { printer->Print( - // With static initializers. - " DO_(_extensions_.ParseField(tag, input, " - "internal_default_instance());\n"); + " DO_(_extensions_.ParseField(tag, input,\n" + " internal_default_instance(),\n" + " &unknown_fields_stream));\n"); } printer->Print( " continue;\n" @@ -3509,19 +3844,14 @@ GenerateMergeFromCodedStream(io::Printer* printer) { } // We really don't recognize this tag. Skip it. - if (PreserveUnknownFields(descriptor_)) { - if (UseUnknownFieldSet(descriptor_->file(), options_)) { - printer->Print( + if (UseUnknownFieldSet(descriptor_->file(), options_)) { + printer->Print(vars, "DO_(::google::protobuf::internal::WireFormat::SkipField(\n" - " input, tag, mutable_unknown_fields()));\n"); - } else { - printer->Print( - "DO_(::google::protobuf::internal::WireFormatLite::SkipField(\n" - " input, tag, &unknown_fields_stream));\n"); - } + " input, tag, $mutable_unknown_fields$));\n"); } else { printer->Print( - "DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag));\n"); + "DO_(::google::protobuf::internal::WireFormatLite::SkipField(\n" + " input, tag, &unknown_fields_stream));\n"); } if (descriptor_->field_count() > 0) { @@ -3658,13 +3988,16 @@ GenerateSerializeWithCachedSizes(io::Printer* printer) { " _extensions_.SerializeMessageSetWithCachedSizes(output);\n", "classname", classname_); GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file(), options_)); - printer->Print( + std::map<string, string> vars; + SetUnknkownFieldsVariable(descriptor_, options_, &vars); + printer->Print(vars, " ::google::protobuf::internal::WireFormat::SerializeUnknownMessageSetItems(\n" - " unknown_fields(), output);\n"); + " $unknown_fields$, output);\n"); printer->Print( "}\n"); return; } + if (options_.table_driven_serialization) return; printer->Print( "void $classname$::SerializeWithCachedSizes(\n" @@ -3699,10 +4032,12 @@ GenerateSerializeWithCachedSizesToArray(io::Printer* printer) { " deterministic, target);\n", "classname", classname_); GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file(), options_)); - printer->Print( + std::map<string, string> vars; + SetUnknkownFieldsVariable(descriptor_, options_, &vars); + printer->Print(vars, " target = ::google::protobuf::internal::WireFormat::\n" " SerializeUnknownMessageSetItemsToArray(\n" - " unknown_fields(), target);\n"); + " $unknown_fields$, target);\n"); printer->Print( " return target;\n" "}\n"); @@ -3866,29 +4201,29 @@ GenerateSerializeWithCachedSizesBody(io::Printer* printer, bool to_array) { } } - if (PreserveUnknownFields(descriptor_)) { - if (UseUnknownFieldSet(descriptor_->file(), options_)) { - printer->Print("if (_internal_metadata_.have_unknown_fields()) {\n"); - printer->Indent(); - if (to_array) { - printer->Print( - "target = " - "::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(\n" - " unknown_fields(), target);\n"); - } else { - printer->Print( - "::google::protobuf::internal::WireFormat::SerializeUnknownFields(\n" - " unknown_fields(), output);\n"); - } - printer->Outdent(); - - printer->Print( - "}\n"); + std::map<string, string> vars; + SetUnknkownFieldsVariable(descriptor_, options_, &vars); + if (UseUnknownFieldSet(descriptor_->file(), options_)) { + printer->Print(vars, + "if ($have_unknown_fields$) {\n"); + printer->Indent(); + if (to_array) { + printer->Print(vars, + "target = " + "::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray(\n" + " $unknown_fields$, target);\n"); } else { - printer->Print( - "output->WriteRaw(unknown_fields().data(),\n" - " static_cast<int>(unknown_fields().size()));\n"); + printer->Print(vars, + "::google::protobuf::internal::WireFormat::SerializeUnknownFields(\n" + " $unknown_fields$, output);\n"); } + printer->Outdent(); + + printer->Print("}\n"); + } else { + printer->Print(vars, + "output->WriteRaw($unknown_fields$.data(),\n" + " static_cast<int>($unknown_fields$.size()));\n"); } } @@ -3932,18 +4267,19 @@ void MessageGenerator:: GenerateByteSize(io::Printer* printer) { if (descriptor_->options().message_set_wire_format()) { // Special-case MessageSet. - printer->Print( - "size_t $classname$::ByteSizeLong() const {\n" - "// @@protoc_insertion_point(message_set_byte_size_start:$full_name$)\n" - " size_t total_size = _extensions_.MessageSetByteSize();\n", - "classname", classname_, "full_name", descriptor_->full_name()); GOOGLE_CHECK(UseUnknownFieldSet(descriptor_->file(), options_)); - printer->Print( - "if (_internal_metadata_.have_unknown_fields()) {\n" - " total_size += ::google::protobuf::internal::WireFormat::\n" - " ComputeUnknownMessageSetItemsSize(unknown_fields());\n" - "}\n"); - printer->Print( + std::map<string, string> vars; + SetUnknkownFieldsVariable(descriptor_, options_, &vars); + vars["classname"] = classname_; + vars["full_name"] = descriptor_->full_name(); + printer->Print(vars, + "size_t $classname$::ByteSizeLong() const {\n" + "// @@protoc_insertion_point(message_set_byte_size_start:$full_name$)\n" + " size_t total_size = _extensions_.MessageSetByteSize();\n" + " if ($have_unknown_fields$) {\n" + " total_size += ::google::protobuf::internal::WireFormat::\n" + " ComputeUnknownMessageSetItemsSize($unknown_fields$);\n" + " }\n" " int cached_size = ::google::protobuf::internal::ToCachedSize(total_size);\n" " GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN();\n" " _cached_size_ = cached_size;\n" @@ -3997,19 +4333,19 @@ GenerateByteSize(io::Printer* printer) { "\n"); } - if (PreserveUnknownFields(descriptor_)) { - if (UseUnknownFieldSet(descriptor_->file(), options_)) { - printer->Print( - "if (_internal_metadata_.have_unknown_fields()) {\n" - " total_size +=\n" - " ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(\n" - " unknown_fields());\n" - "}\n"); - } else { - printer->Print( - "total_size += unknown_fields().size();\n" - "\n"); - } + std::map<string, string> vars; + SetUnknkownFieldsVariable(descriptor_, options_, &vars); + if (UseUnknownFieldSet(descriptor_->file(), options_)) { + printer->Print(vars, + "if ($have_unknown_fields$) {\n" + " total_size +=\n" + " ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize(\n" + " $unknown_fields$);\n" + "}\n"); + } else { + printer->Print(vars, + "total_size += $unknown_fields$.size();\n" + "\n"); } // Handle required fields (if any). We expect all of them to be @@ -4358,7 +4694,6 @@ GenerateIsInitialized(io::Printer* printer) { "}\n"); } - } // namespace cpp } // namespace compiler } // namespace protobuf diff --git a/src/google/protobuf/compiler/cpp/cpp_message.h b/src/google/protobuf/compiler/cpp/cpp_message.h index 23aaeeb0..352069eb 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message.h +++ b/src/google/protobuf/compiler/cpp/cpp_message.h @@ -104,10 +104,6 @@ class MessageGenerator { // allocated before any can be initialized. void GenerateDefaultInstanceInitializer(io::Printer* printer); - // Generates code that should be run when ShutdownProtobufLibrary() is called, - // to delete all dynamically-allocated objects. - void GenerateShutdownCode(io::Printer* printer); - // Generate all non-inline methods for this class. void GenerateClassMethods(io::Printer* printer); @@ -132,6 +128,9 @@ class MessageGenerator { // of entries generated and the index of the first has_bit entry. std::pair<size_t, size_t> GenerateOffsets(io::Printer* printer); void GenerateSchema(io::Printer* printer, int offset, int has_offset); + // For each field generates a table entry describing the field for the + // table driven serializer. + int GenerateFieldMetadata(io::Printer* printer); // Generate constructors and destructor. void GenerateStructors(io::Printer* printer); @@ -147,6 +146,13 @@ class MessageGenerator { // Generate the arena-specific destructor code. void GenerateArenaDestructorCode(io::Printer* printer); + // Helper for GenerateClear and others. Optionally emits a condition that + // assumes the existence of the cached_has_bits variable, and returns true if + // the condition was printed. + bool MaybeGenerateOptionalFieldCondition(io::Printer* printer, + const FieldDescriptor* field, + int expected_has_bits_index); + // Generate standard Message methods. void GenerateClear(io::Printer* printer); void GenerateOneofClear(io::Printer* printer); @@ -179,7 +185,6 @@ class MessageGenerator { io::Printer* printer, const Descriptor::ExtensionRange* range, bool unbounded); - // Generates has_foo() functions and variables for singular field has-bits. void GenerateSingularFieldHasBits(const FieldDescriptor* field, std::map<string, string> vars, diff --git a/src/google/protobuf/compiler/cpp/cpp_message_field.cc b/src/google/protobuf/compiler/cpp/cpp_message_field.cc index fc3c4564..e45470fb 100644 --- a/src/google/protobuf/compiler/cpp/cpp_message_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_message_field.cc @@ -50,6 +50,8 @@ void SetMessageVariables(const FieldDescriptor* descriptor, const Options& options) { SetCommonFieldVariables(descriptor, variables, options); (*variables)["type"] = FieldMessageTypeName(descriptor); + (*variables)["type_default_instance"] = + DefaultInstanceName(descriptor->message_type()); if (descriptor->options().weak() || !descriptor->containing_oneof()) { (*variables)["non_null_ptr_to_name"] = StrCat("this->", (*variables)["name"], "_"); @@ -98,6 +100,7 @@ void MessageFieldGenerator:: GenerateGetterDeclaration(io::Printer* printer) const { printer->Print(variables_, "$deprecated_attr$const $type$& $name$() const;\n"); + printer->Annotate("name", descriptor_); } void MessageFieldGenerator:: @@ -107,9 +110,14 @@ GenerateDependentAccessorDeclarations(io::Printer* printer) const { } // Arena manipulation code is out-of-line in the derived message class. printer->Print(variables_, - "$deprecated_attr$$type$* mutable_$name$();\n" - "$deprecated_attr$$type$* $release_name$();\n" - "$deprecated_attr$void set_allocated_$name$($type$* $name$);\n"); + "$deprecated_attr$$type$* ${$mutable_$name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, "$deprecated_attr$$type$* $release_name$();\n"); + printer->Annotate("release_name", descriptor_); + printer->Print(variables_, + "$deprecated_attr$void ${$set_allocated_$name$$}$" + "($type$* $name$);\n"); + printer->Annotate("{", "}", descriptor_); } void MessageFieldGenerator:: @@ -130,15 +138,25 @@ GenerateAccessorDeclarations(io::Printer* printer) const { GenerateGetterDeclaration(printer); if (!dependent_field_) { printer->Print(variables_, - "$deprecated_attr$$type$* mutable_$name$();\n" - "$deprecated_attr$$type$* $release_name$();\n" - "$deprecated_attr$void set_allocated_$name$($type$* $name$);\n"); + "$deprecated_attr$$type$* ${$mutable_$name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, "$deprecated_attr$$type$* $release_name$();\n"); + printer->Annotate("release_name", descriptor_); + printer->Print(variables_, + "$deprecated_attr$void ${$set_allocated_$name$$}$" + "($type$* $name$);\n"); + printer->Annotate("{", "}", descriptor_); } if (SupportsArenas(descriptor_)) { + printer->Print( + variables_, + "$deprecated_attr$$type$* ${$unsafe_arena_release_$name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); printer->Print(variables_, - "$deprecated_attr$$type$* unsafe_arena_release_$name$();\n" - "$deprecated_attr$void unsafe_arena_set_allocated_$name$(\n" - " $type$* $name$);\n"); + "$deprecated_attr$void " + "${$unsafe_arena_set_allocated_$name$$}$(\n" + " $type$* $name$);\n"); + printer->Annotate("{", "}", descriptor_); } } @@ -346,30 +364,18 @@ GenerateDependentInlineAccessorDefinitions(io::Printer* printer) const { void MessageFieldGenerator:: GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { - if (dependent_field_) { - // for dependent fields we cannot access its internal_default_instance, - // because the type is incomplete. - // TODO(gerbens) deprecate dependent base class. - std::map<string, string> variables(variables_); - variables["inline"] = is_inline ? "inline " : ""; - printer->Print(variables, - "$inline$const $type$& $classname$::$name$() const {\n" - " // @@protoc_insertion_point(field_get:$full_name$)\n" - " return $name$_ != NULL ? *$name$_\n" - " : *internal_default_instance()->$name$_;\n" - "}\n"); - return; - } - std::map<string, string> variables(variables_); variables["inline"] = is_inline ? "inline " : ""; printer->Print(variables, "$inline$const $type$& $classname$::$name$() const {\n" + " const $type$* p = $name$_;\n" " // @@protoc_insertion_point(field_get:$full_name$)\n" - " return $name$_ != NULL ? *$name$_\n" - " : *$type$::internal_default_instance();\n" + " return p != NULL ? *p : *reinterpret_cast<const $type$*>(\n" + " &$type_default_instance$);\n" "}\n"); + if (dependent_field_) return; + if (SupportsArenas(descriptor_)) { printer->Print(variables, "$inline$" @@ -511,18 +517,12 @@ GenerateMergingCode(io::Printer* printer) const { void MessageFieldGenerator:: GenerateSwappingCode(io::Printer* printer) const { - printer->Print(variables_, "std::swap($name$_, other->$name$_);\n"); + printer->Print(variables_, "swap($name$_, other->$name$_);\n"); } void MessageFieldGenerator:: GenerateDestructorCode(io::Printer* printer) const { - // In google3 a default instance will never get deleted so we don't need to - // worry about that but in opensource protobuf default instances are deleted - // in shutdown process and we need to take special care when handling them. - printer->Print(variables_, - "if (this != internal_default_instance()) {\n" - " delete $name$_;\n" - "}\n"); + printer->Print(variables_, "delete $name$_;\n"); } void MessageFieldGenerator:: @@ -899,16 +899,20 @@ GeneratePrivateMembers(io::Printer* printer) const { void RepeatedMessageFieldGenerator:: InternalGenerateTypeDependentAccessorDeclarations(io::Printer* printer) const { printer->Print(variables_, - "$deprecated_attr$$type$* mutable_$name$(int index);\n" - "$deprecated_attr$$type$* add_$name$();\n"); + "$deprecated_attr$$type$* ${$mutable_$name$$}$(int index);\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, "$deprecated_attr$$type$* ${$add_$name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); if (dependent_getter_) { printer->Print(variables_, "$deprecated_attr$const ::google::protobuf::RepeatedPtrField< $type$ >&\n" " $name$() const;\n"); + printer->Annotate("name", descriptor_); } printer->Print(variables_, - "$deprecated_attr$::google::protobuf::RepeatedPtrField< $type$ >*\n" - " mutable_$name$();\n"); + "$deprecated_attr$::google::protobuf::RepeatedPtrField< $type$ >*\n" + " ${$mutable_$name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); } void RepeatedMessageFieldGenerator:: @@ -916,6 +920,7 @@ GenerateDependentAccessorDeclarations(io::Printer* printer) const { if (dependent_getter_) { printer->Print(variables_, "$deprecated_attr$const $type$& $name$(int index) const;\n"); + printer->Annotate("name", descriptor_); } if (dependent_field_) { InternalGenerateTypeDependentAccessorDeclarations(printer); @@ -927,6 +932,7 @@ GenerateAccessorDeclarations(io::Printer* printer) const { if (!dependent_getter_) { printer->Print(variables_, "$deprecated_attr$const $type$& $name$(int index) const;\n"); + printer->Annotate("name", descriptor_); } if (!dependent_field_) { InternalGenerateTypeDependentAccessorDeclarations(printer); @@ -935,6 +941,7 @@ GenerateAccessorDeclarations(io::Printer* printer) const { printer->Print(variables_, "$deprecated_attr$const ::google::protobuf::RepeatedPtrField< $type$ >&\n" " $name$() const;\n"); + printer->Annotate("name", descriptor_); } } diff --git a/src/google/protobuf/compiler/cpp/cpp_move_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_move_unittest.cc new file mode 100644 index 00000000..f72a7d60 --- /dev/null +++ b/src/google/protobuf/compiler/cpp/cpp_move_unittest.cc @@ -0,0 +1,169 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <google/protobuf/stubs/common.h> +#include <google/protobuf/test_util.h> +#include <google/protobuf/unittest.pb.h> +#include <gtest/gtest.h> + +#if LANG_CXX11 +#include <google/protobuf/stubs/type_traits.h> +#endif + +namespace google { +namespace protobuf { +namespace compiler { +namespace cpp { + +// Can't use an anonymous namespace here due to brokenness of Tru64 compiler. +namespace cpp_unittest { + +// Moves are enabled only when compiling with a C++11 compiler or newer. +#if LANG_CXX11 + +TEST(MovableMessageTest, MoveConstructor) { + protobuf_unittest::TestAllTypes message1; + TestUtil::SetAllFields(&message1); + const auto* nested = &message1.optional_nested_message(); + + protobuf_unittest::TestAllTypes message2(std::move(message1)); + TestUtil::ExpectAllFieldsSet(message2); + + // Check if the optional_nested_message was actually moved (and not just + // copied). + EXPECT_EQ(nested, &message2.optional_nested_message()); + EXPECT_NE(nested, &message1.optional_nested_message()); +} + +TEST(MovableMessageTest, MoveAssignmentOperator) { + protobuf_unittest::TestAllTypes message1; + TestUtil::SetAllFields(&message1); + const auto* nested = &message1.optional_nested_message(); + + protobuf_unittest::TestAllTypes message2; + message2 = std::move(message1); + TestUtil::ExpectAllFieldsSet(message2); + + // Check if the optional_nested_message was actually moved (and not just + // copied). + EXPECT_EQ(nested, &message2.optional_nested_message()); + EXPECT_NE(nested, &message1.optional_nested_message()); +} + +TEST(MovableMessageTest, SelfMoveAssignment) { + // The `self` reference is necessary to defeat -Wself-move. + protobuf_unittest::TestAllTypes message, &self = message; + TestUtil::SetAllFields(&message); + message = std::move(self); + TestUtil::ExpectAllFieldsSet(message); +} + +TEST(MovableMessageTest, MoveSameArena) { + Arena arena; + + auto* message1_on_arena = + Arena::CreateMessage<protobuf_unittest::TestAllTypes>(&arena); + TestUtil::SetAllFields(message1_on_arena); + const auto* nested = &message1_on_arena->optional_nested_message(); + + auto* message2_on_arena = + Arena::CreateMessage<protobuf_unittest::TestAllTypes>(&arena); + + // Moving messages on the same arena should lead to swapped pointers. + *message2_on_arena = std::move(*message1_on_arena); + EXPECT_EQ(nested, &message2_on_arena->optional_nested_message()); +} + +TEST(MovableMessageTest, MoveDifferentArenas) { + Arena arena1, arena2; + + auto* message1_on_arena = + Arena::CreateMessage<protobuf_unittest::TestAllTypes>(&arena1); + TestUtil::SetAllFields(message1_on_arena); + const auto* nested = &message1_on_arena->optional_nested_message(); + + auto* message2_on_arena = + Arena::CreateMessage<protobuf_unittest::TestAllTypes>(&arena2); + + // Moving messages on two different arenas should lead to a copy. + *message2_on_arena = std::move(*message1_on_arena); + EXPECT_NE(nested, &message2_on_arena->optional_nested_message()); + TestUtil::ExpectAllFieldsSet(*message1_on_arena); + TestUtil::ExpectAllFieldsSet(*message2_on_arena); +} + +TEST(MovableMessageTest, MoveFromArena) { + Arena arena; + + auto* message1_on_arena = + Arena::CreateMessage<protobuf_unittest::TestAllTypes>(&arena); + TestUtil::SetAllFields(message1_on_arena); + const auto* nested = &message1_on_arena->optional_nested_message(); + + protobuf_unittest::TestAllTypes message2; + + // Moving from a message on the arena should lead to a copy. + message2 = std::move(*message1_on_arena); + EXPECT_NE(nested, &message2.optional_nested_message()); + TestUtil::ExpectAllFieldsSet(*message1_on_arena); + TestUtil::ExpectAllFieldsSet(message2); +} + +TEST(MovableMessageTest, MoveToArena) { + Arena arena; + + protobuf_unittest::TestAllTypes message1; + TestUtil::SetAllFields(&message1); + const auto* nested = &message1.optional_nested_message(); + + auto* message2_on_arena = + Arena::CreateMessage<protobuf_unittest::TestAllTypes>(&arena); + + // Moving to a message on the arena should lead to a copy. + *message2_on_arena = std::move(message1); + EXPECT_NE(nested, &message2_on_arena->optional_nested_message()); + TestUtil::ExpectAllFieldsSet(message1); + TestUtil::ExpectAllFieldsSet(*message2_on_arena); +} + +TEST(MovableMessageTest, Noexcept) { + EXPECT_TRUE( + std::is_nothrow_move_constructible<protobuf_unittest::TestAllTypes>()); + EXPECT_TRUE(std::is_nothrow_move_assignable<protobuf_unittest::TestAllTypes>()); +} + +#endif // LANG_CXX11 + +} // namespace cpp_unittest + +} // namespace cpp +} // namespace compiler +} // namespace protobuf +} // namespace google diff --git a/src/google/protobuf/compiler/cpp/cpp_options.h b/src/google/protobuf/compiler/cpp/cpp_options.h index bdaa12a5..04338083 100644 --- a/src/google/protobuf/compiler/cpp/cpp_options.h +++ b/src/google/protobuf/compiler/cpp/cpp_options.h @@ -49,7 +49,8 @@ struct Options { transitive_pb_h(true), annotate_headers(false), enforce_lite(false), - table_driven_parsing(false) {} + table_driven_parsing(false), + table_driven_serialization(false) {} string dllexport_decl; bool safe_boundary_check; @@ -58,6 +59,7 @@ struct Options { bool annotate_headers; bool enforce_lite; bool table_driven_parsing; + bool table_driven_serialization; string annotation_pragma_name; string annotation_guard_name; }; diff --git a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc index 020c1941..07ac0bb4 100644 --- a/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_primitive_field.cc @@ -115,9 +115,11 @@ GeneratePrivateMembers(io::Printer* printer) const { void PrimitiveFieldGenerator:: GenerateAccessorDeclarations(io::Printer* printer) const { + printer->Print(variables_, "$deprecated_attr$$type$ $name$() const;\n"); + printer->Annotate("name", descriptor_); printer->Print(variables_, - "$deprecated_attr$$type$ $name$() const;\n" - "$deprecated_attr$void set_$name$($type$ value);\n"); + "$deprecated_attr$void ${$set_$name$$}$($type$ value);\n"); + printer->Annotate("{", "}", descriptor_); } void PrimitiveFieldGenerator:: @@ -148,7 +150,7 @@ GenerateMergingCode(io::Printer* printer) const { void PrimitiveFieldGenerator:: GenerateSwappingCode(io::Printer* printer) const { - printer->Print(variables_, "std::swap($name$_, other->$name$_);\n"); + printer->Print(variables_, "swap($name$_, other->$name$_);\n"); } void PrimitiveFieldGenerator:: @@ -290,14 +292,23 @@ GeneratePrivateMembers(io::Printer* printer) const { void RepeatedPrimitiveFieldGenerator:: GenerateAccessorDeclarations(io::Printer* printer) const { printer->Print(variables_, - "$deprecated_attr$$type$ $name$(int index) const;\n" - "$deprecated_attr$void set_$name$(int index, $type$ value);\n" - "$deprecated_attr$void add_$name$($type$ value);\n"); + "$deprecated_attr$$type$ $name$(int index) const;\n"); + printer->Annotate("name", descriptor_); + printer->Print( + variables_, + "$deprecated_attr$void ${$set_$name$$}$(int index, $type$ value);\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "$deprecated_attr$void ${$add_$name$$}$($type$ value);\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "$deprecated_attr$const ::google::protobuf::RepeatedField< $type$ >&\n" + " $name$() const;\n"); + printer->Annotate("name", descriptor_); printer->Print(variables_, - "$deprecated_attr$const ::google::protobuf::RepeatedField< $type$ >&\n" - " $name$() const;\n" - "$deprecated_attr$::google::protobuf::RepeatedField< $type$ >*\n" - " mutable_$name$();\n"); + "$deprecated_attr$::google::protobuf::RepeatedField< $type$ >*\n" + " ${$mutable_$name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); } void RepeatedPrimitiveFieldGenerator:: @@ -316,8 +327,7 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, bool is_inline) const { "$inline$void $classname$::add_$name$($type$ value) {\n" " $name$_.Add(value);\n" " // @@protoc_insertion_point(field_add:$full_name$)\n" - "}\n"); - printer->Print(variables, + "}\n" "$inline$const ::google::protobuf::RepeatedField< $type$ >&\n" "$classname$::$name$() const {\n" " // @@protoc_insertion_point(field_list:$full_name$)\n" diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.cc b/src/google/protobuf/compiler/cpp/cpp_string_field.cc index 7a849e2e..c23dd6fd 100644 --- a/src/google/protobuf/compiler/cpp/cpp_string_field.cc +++ b/src/google/protobuf/compiler/cpp/cpp_string_field.cc @@ -142,28 +142,47 @@ GenerateAccessorDeclarations(io::Printer* printer) const { } printer->Print(variables_, - "$deprecated_attr$const ::std::string& $name$() const;\n" - "$deprecated_attr$void set_$name$(const ::std::string& value);\n"); + "$deprecated_attr$const ::std::string& $name$() const;\n"); + printer->Annotate("name", descriptor_); + printer->Print( + variables_, + "$deprecated_attr$void ${$set_$name$$}$(const ::std::string& value);\n"); + printer->Annotate("{", "}", descriptor_); - if (!SupportsArenas(descriptor_)) { - printer->Print(variables_, - "#if LANG_CXX11\n" - "$deprecated_attr$void set_$name$(::std::string&& value);\n" - "#endif\n"); - } + printer->Print(variables_, + "#if LANG_CXX11\n" + "$deprecated_attr$void ${$set_$name$$}$(::std::string&& value);\n" + "#endif\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print( + variables_, + "$deprecated_attr$void ${$set_$name$$}$(const char* value);\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "$deprecated_attr$void ${$set_$name$$}$(const $pointer_type$* " + "value, size_t size)" + ";\n"); + printer->Annotate("{", "}", descriptor_); printer->Print(variables_, - "$deprecated_attr$void set_$name$(const char* value);\n" - "$deprecated_attr$void set_$name$(const $pointer_type$* value, size_t size)" - ";\n" - "$deprecated_attr$::std::string* mutable_$name$();\n" - "$deprecated_attr$::std::string* $release_name$();\n" - "$deprecated_attr$void set_allocated_$name$(::std::string* $name$);\n"); + "$deprecated_attr$::std::string* ${$mutable_$name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, "$deprecated_attr$::std::string* $release_name$();\n"); + printer->Annotate("release_name", descriptor_); + printer->Print( + variables_, + "$deprecated_attr$void ${$set_allocated_$name$$}$(::std::string* $name$);\n"); + printer->Annotate("{", "}", descriptor_); if (SupportsArenas(descriptor_)) { - printer->Print(variables_, - "$deprecated_attr$::std::string* unsafe_arena_release_$name$();\n" - "$deprecated_attr$void unsafe_arena_set_allocated_$name$(\n" - " ::std::string* $name$);\n"); + printer->Print( + variables_, + "$deprecated_attr$::std::string* ${$unsafe_arena_release_$name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print( + variables_, + "$deprecated_attr$void ${$unsafe_arena_set_allocated_$name$$}$(\n" + " ::std::string* $name$);\n"); + printer->Annotate("{", "}", descriptor_); } @@ -191,6 +210,14 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " $name$_.Set($default_variable$, value, GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" + "#if LANG_CXX11\n" + "$inline$void $classname$::set_$name$(::std::string&& value) {\n" + " $set_hasbit$\n" + " $name$_.Set(\n" + " $default_variable$, ::std::move(value), GetArenaNoVirtual());\n" + " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n" + "}\n" + "#endif\n" "$inline$void $classname$::set_$name$(const char* value) {\n" " $null_check$" " $set_hasbit$\n" @@ -456,15 +483,10 @@ GenerateDefaultInstanceAllocator(io::Printer* printer) const { printer->Print(variables_, "$classname$::$default_variable_name$.DefaultConstruct();\n" "*$classname$::$default_variable_name$.get_mutable() = " - "::std::string($default$, $default_length$);\n"); - } -} - -void StringFieldGenerator:: -GenerateShutdownCode(io::Printer* printer) const { - if (!descriptor_->default_value_string().empty()) { - printer->Print(variables_, - "$classname$::$default_variable_name$.Shutdown();\n"); + "::std::string($default$, $default_length$);\n" + "::google::protobuf::internal::OnShutdownDestroyString(\n" + " $classname$::$default_variable_name$.get_mutable());\n" + ); } } @@ -551,6 +573,19 @@ GenerateInlineAccessorDefinitions(io::Printer* printer, " GetArenaNoVirtual());\n" " // @@protoc_insertion_point(field_set:$full_name$)\n" "}\n" + "#if LANG_CXX11\n" + "$inline$void $classname$::set_$name$(::std::string&& value) {\n" + " // @@protoc_insertion_point(field_set:$full_name$)\n" + " if (!has_$name$()) {\n" + " clear_$oneof_name$();\n" + " set_has_$name$();\n" + " $oneof_prefix$$name$_.UnsafeSetDefault($default_variable$);\n" + " }\n" + " $oneof_prefix$$name$_.Set(\n" + " $default_variable$, ::std::move(value), GetArenaNoVirtual());\n" + " // @@protoc_insertion_point(field_set_rvalue:$full_name$)\n" + "}\n" + "#endif\n" "$inline$void $classname$::set_$name$(const char* value) {\n" " $null_check$" " if (!has_$name$()) {\n" @@ -833,28 +868,62 @@ GenerateAccessorDeclarations(io::Printer* printer) const { } printer->Print(variables_, - "$deprecated_attr$const ::std::string& $name$(int index) const;\n" - "$deprecated_attr$::std::string* mutable_$name$(int index);\n" - "$deprecated_attr$void set_$name$(int index, const ::std::string& value);\n" - "#if LANG_CXX11\n" - "$deprecated_attr$void set_$name$(int index, ::std::string&& value);\n" - "#endif\n" - "$deprecated_attr$void set_$name$(int index, const char* value);\n" - "" - "$deprecated_attr$void set_$name$(" - "int index, const $pointer_type$* value, size_t size);\n" - "$deprecated_attr$::std::string* add_$name$();\n" - "$deprecated_attr$void add_$name$(const ::std::string& value);\n" - "#if LANG_CXX11\n" - "$deprecated_attr$void add_$name$(::std::string&& value);\n" - "#endif\n" - "$deprecated_attr$void add_$name$(const char* value);\n" - "$deprecated_attr$void add_$name$(const $pointer_type$* value, size_t size)" - ";\n" - "$deprecated_attr$const ::google::protobuf::RepeatedPtrField< ::std::string>& $name$() " - "const;\n" - "$deprecated_attr$::google::protobuf::RepeatedPtrField< ::std::string>* mutable_$name$()" + "$deprecated_attr$const ::std::string& $name$(int index) const;\n"); + printer->Annotate("name", descriptor_); + printer->Print( + variables_, + "$deprecated_attr$::std::string* ${$mutable_$name$$}$(int index);\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "$deprecated_attr$void ${$set_$name$$}$(int index, const " + "::std::string& value);\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print( + variables_, + "#if LANG_CXX11\n" + "$deprecated_attr$void ${$set_$name$$}$(int index, ::std::string&& value);\n" + "#endif\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "$deprecated_attr$void ${$set_$name$$}$(int index, const " + "char* value);\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "" + "$deprecated_attr$void ${$set_$name$$}$(" + "int index, const $pointer_type$* value, size_t size);\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "$deprecated_attr$::std::string* ${$add_$name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print( + variables_, + "$deprecated_attr$void ${$add_$name$$}$(const ::std::string& value);\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "#if LANG_CXX11\n" + "$deprecated_attr$void ${$add_$name$$}$(::std::string&& value);\n" + "#endif\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print( + variables_, + "$deprecated_attr$void ${$add_$name$$}$(const char* value);\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print(variables_, + "$deprecated_attr$void ${$add_$name$$}$(const $pointer_type$* " + "value, size_t size)" + ";\n"); + printer->Annotate("{", "}", descriptor_); + printer->Print( + variables_, + "$deprecated_attr$const ::google::protobuf::RepeatedPtrField< ::std::string>& $name$() " + "const;\n"); + printer->Annotate("name", descriptor_); + printer->Print(variables_, + "$deprecated_attr$::google::protobuf::RepeatedPtrField< ::std::string>* " + "${$mutable_$name$$}$()" ";\n"); + printer->Annotate("{", "}", descriptor_); if (unknown_ctype) { printer->Outdent(); diff --git a/src/google/protobuf/compiler/cpp/cpp_string_field.h b/src/google/protobuf/compiler/cpp/cpp_string_field.h index af263c1a..531252b0 100644 --- a/src/google/protobuf/compiler/cpp/cpp_string_field.h +++ b/src/google/protobuf/compiler/cpp/cpp_string_field.h @@ -65,7 +65,6 @@ class StringFieldGenerator : public FieldGenerator { void GenerateCopyConstructorCode(io::Printer* printer) const; void GenerateDestructorCode(io::Printer* printer) const; void GenerateDefaultInstanceAllocator(io::Printer* printer) const; - void GenerateShutdownCode(io::Printer* printer) const; void GenerateMergeFromCodedStream(io::Printer* printer) const; void GenerateSerializeWithCachedSizes(io::Printer* printer) const; void GenerateSerializeWithCachedSizesToArray(io::Printer* printer) const; diff --git a/src/google/protobuf/compiler/cpp/cpp_unittest.cc b/src/google/protobuf/compiler/cpp/cpp_unittest.cc index e56964c7..fdde771b 100644 --- a/src/google/protobuf/compiler/cpp/cpp_unittest.cc +++ b/src/google/protobuf/compiler/cpp/cpp_unittest.cc @@ -576,12 +576,73 @@ TEST(GeneratedMessageTest, SwapWithOther) { EXPECT_EQ(unittest::TestAllTypes::BAR, message2.repeated_nested_enum(1)); } -TEST(GeneratedMessageTest, CopyConstructor) { - unittest::TestAllTypes message1; +TEST(GeneratedMessageTest, ADLSwap) { + unittest::TestAllTypes message1, message2; TestUtil::SetAllFields(&message1); - unittest::TestAllTypes message2(message1); + // Note the address of one of the repeated fields, to verify it was swapped + // rather than copied. + const int32* addr = &message1.repeated_int32().Get(0); + + using std::swap; + swap(message1, message2); + TestUtil::ExpectAllFieldsSet(message2); + TestUtil::ExpectClear(message1); + + EXPECT_EQ(addr, &message2.repeated_int32().Get(0)); +} + +TEST(GeneratedMessageTest, CopyConstructor) { + // All set. + { + unittest::TestAllTypes message1; + TestUtil::SetAllFields(&message1); + + unittest::TestAllTypes message2(message1); + TestUtil::ExpectAllFieldsSet(message2); + } + + // None set. + { + unittest::TestAllTypes message1; + unittest::TestAllTypes message2(message1); + + EXPECT_FALSE(message1.has_optional_string()); + EXPECT_FALSE(message2.has_optional_string()); + EXPECT_EQ(&message1.optional_string(), + &message2.optional_string()); + + EXPECT_FALSE(message1.has_optional_bytes()); + EXPECT_FALSE(message2.has_optional_bytes()); + EXPECT_EQ(&message1.optional_bytes(), + &message2.optional_bytes()); + + EXPECT_FALSE(message1.has_optional_nested_message()); + EXPECT_FALSE(message2.has_optional_nested_message()); + EXPECT_EQ(&message1.optional_nested_message(), + &message2.optional_nested_message()); + + EXPECT_FALSE(message1.has_optional_foreign_message()); + EXPECT_FALSE(message2.has_optional_foreign_message()); + EXPECT_EQ(&message1.optional_foreign_message(), + &message2.optional_foreign_message()); + + EXPECT_FALSE(message1.has_optional_import_message()); + EXPECT_FALSE(message2.has_optional_import_message()); + EXPECT_EQ(&message1.optional_import_message(), + &message2.optional_import_message()); + + EXPECT_FALSE(message1.has_optional_public_import_message()); + EXPECT_FALSE(message2.has_optional_public_import_message()); + EXPECT_EQ(&message1.optional_public_import_message(), + &message2.optional_public_import_message()); + + EXPECT_FALSE(message1.has_optional_lazy_message()); + EXPECT_FALSE(message2.has_optional_lazy_message()); + EXPECT_EQ(&message1.optional_lazy_message(), + &message2.optional_lazy_message()); + } } TEST(GeneratedMessageTest, CopyConstructorWithArenas) { @@ -1340,7 +1401,7 @@ class GeneratedServiceTest : public testing::Test { foo_(descriptor_->FindMethodByName("Foo")), bar_(descriptor_->FindMethodByName("Bar")), stub_(&mock_channel_), - done_(NewPermanentCallback(&DoNothing)) {} + done_(::google::protobuf::NewPermanentCallback(&DoNothing)) {} virtual void SetUp() { ASSERT_TRUE(foo_ != NULL); diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc index 844edc1c..a27562f7 100644 --- a/src/google/protobuf/compiler/importer.cc +++ b/src/google/protobuf/compiler/importer.cc @@ -32,6 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. + #ifdef _MSC_VER #include <io.h> #else @@ -295,10 +296,8 @@ static string CanonicalizePath(string path) { } static inline bool ContainsParentReference(const string& path) { - return path == ".." || - HasPrefixString(path, "../") || - HasSuffixString(path, "/..") || - path.find("/../") != string::npos; + return path == ".." || HasPrefixString(path, "../") || + HasSuffixString(path, "/..") || path.find("/../") != string::npos; } // Maps a file from an old location to a new one. Typically, old_prefix is @@ -328,8 +327,7 @@ static bool ApplyMapping(const string& filename, // We do not allow the file name to use "..". return false; } - if (HasPrefixString(filename, "/") || - IsWindowsAbsolutePath(filename)) { + if (HasPrefixString(filename, "/") || IsWindowsAbsolutePath(filename)) { // This is an absolute path, so it isn't matched by the empty string. return false; } diff --git a/src/google/protobuf/compiler/java/java_context.cc b/src/google/protobuf/compiler/java/java_context.cc index b82fb3dd..0771d5e1 100644 --- a/src/google/protobuf/compiler/java/java_context.cc +++ b/src/google/protobuf/compiler/java/java_context.cc @@ -50,7 +50,7 @@ Context::Context(const FileDescriptor* file, const Options& options) Context::~Context() { } -ClassNameResolver* Context::GetNameResolver() { +ClassNameResolver* Context::GetNameResolver() const { return name_resolver_.get(); } @@ -154,7 +154,7 @@ void Context::InitializeFieldGeneratorInfoForFields( for (int i = 0; i < fields.size(); ++i) { const FieldDescriptor* field = fields[i]; FieldGeneratorInfo info; - info.name = UnderscoresToCamelCase(field); + info.name = CamelCaseFieldName(field); info.capitalized_name = UnderscoresToCapitalizedCamelCase(field); // For fields conflicting with some other fields, we append the field // number to their field names in generated code to avoid conflicts. diff --git a/src/google/protobuf/compiler/java/java_context.h b/src/google/protobuf/compiler/java/java_context.h index b22e7e3a..9a74c430 100644 --- a/src/google/protobuf/compiler/java/java_context.h +++ b/src/google/protobuf/compiler/java/java_context.h @@ -70,7 +70,7 @@ class Context { // Get the name resolver associated with this context. The resolver // can be used to map descriptors to Java class names. - ClassNameResolver* GetNameResolver(); + ClassNameResolver* GetNameResolver() const; // Get the FieldGeneratorInfo for a given field. const FieldGeneratorInfo* GetFieldGeneratorInfo( diff --git a/src/google/protobuf/compiler/java/java_enum.cc b/src/google/protobuf/compiler/java/java_enum.cc index b9ee00ff..d125ebe5 100644 --- a/src/google/protobuf/compiler/java/java_enum.cc +++ b/src/google/protobuf/compiler/java/java_enum.cc @@ -109,14 +109,16 @@ void EnumGenerator::Generate(io::Printer* printer) { printer->Print(vars, "$name$($index$, $number$),\n"); } + printer->Annotate("name", canonical_values_[i]); } if (SupportUnknownEnumValue(descriptor_->file())) { if (ordinal_is_index) { - printer->Print("UNRECOGNIZED(-1),\n"); + printer->Print("${$UNRECOGNIZED$}$(-1),\n", "{", "", "}", ""); } else { - printer->Print("UNRECOGNIZED(-1, -1),\n"); + printer->Print("${$UNRECOGNIZED$}$(-1, -1),\n", "{", "", "}", ""); } + printer->Annotate("{", "}", descriptor_); } printer->Print( @@ -133,15 +135,19 @@ void EnumGenerator::Generate(io::Printer* printer) { WriteEnumValueDocComment(printer, aliases_[i].value); printer->Print(vars, "public static final $classname$ $name$ = $canonical_name$;\n"); + printer->Annotate("name", aliases_[i].value); } for (int i = 0; i < descriptor_->value_count(); i++) { std::map<string, string> vars; vars["name"] = descriptor_->value(i)->name(); vars["number"] = SimpleItoa(descriptor_->value(i)->number()); + vars["{"] = ""; + vars["}"] = ""; WriteEnumValueDocComment(printer, descriptor_->value(i)); printer->Print(vars, - "public static final int $name$_VALUE = $number$;\n"); + "public static final int ${$$name$_VALUE$}$ = $number$;\n"); + printer->Annotate("{", "}", descriptor_->value(i)); } printer->Print("\n"); diff --git a/src/google/protobuf/compiler/java/java_enum_field.cc b/src/google/protobuf/compiler/java/java_enum_field.cc index 279b9da4..9f7bb349 100644 --- a/src/google/protobuf/compiler/java/java_enum_field.cc +++ b/src/google/protobuf/compiler/java/java_enum_field.cc @@ -183,23 +183,26 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Value() {\n" + "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n" " return $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " $type$ result = $type$.$for_number$($name$_);\n" " return result == null ? $unknown$ : result;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableEnumFieldGenerator:: @@ -209,33 +212,38 @@ GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_builder$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Value() {\n" + "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n" " return $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$Value(int value) {\n" + "$deprecation$public Builder " + "${$set$capitalized_name$Value$}$(int value) {\n" " $name$_ = value;\n" " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " $type$ result = $type$.$for_number$($name$_);\n" " return result == null ? $unknown$ : result;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n" " if (value == null) {\n" " throw new NullPointerException();\n" " }\n" @@ -244,14 +252,16 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " $clear_has_field_bit_builder$\n" " $name$_ = $default_number$;\n" " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableEnumFieldGenerator:: @@ -311,12 +321,8 @@ GenerateParsingCode(io::Printer* printer) const { printer->Print(variables_, "int rawValue = input.readEnum();\n" "$type$ value = $type$.$for_number$(rawValue);\n" - "if (value == null) {\n"); - if (PreserveUnknownFields(descriptor_->containing_type())) { - printer->Print(variables_, - " unknownFields.mergeVarintField($number$, rawValue);\n"); - } - printer->Print(variables_, + "if (value == null) {\n" + " unknownFields.mergeVarintField($number$, rawValue);\n" "} else {\n" " $set_has_field_bit_message$\n" " $name$_ = rawValue;\n" @@ -386,23 +392,25 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Value() {\n" + "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n" " if ($has_oneof_case_message$) {\n" " return (java.lang.Integer) $oneof_name$_;\n" " }\n" " return $default_number$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " $type$ result = $type$.$for_number$(\n" " (java.lang.Integer) $oneof_name$_);\n" @@ -410,6 +418,7 @@ GenerateMembers(io::Printer* printer) const { " }\n" " return $default$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableEnumOneofFieldGenerator:: @@ -417,31 +426,35 @@ GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Value() {\n" + "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n" " if ($has_oneof_case_message$) {\n" " return ((java.lang.Integer) $oneof_name$_).intValue();\n" " }\n" " return $default_number$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$Value(int value) {\n" + "$deprecation$public Builder " + "${$set$capitalized_name$Value$}$(int value) {\n" " $set_oneof_case_message$;\n" " $oneof_name$_ = value;\n" " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " $type$ result = $type$.$for_number$(\n" " (java.lang.Integer) $oneof_name$_);\n" @@ -449,9 +462,10 @@ GenerateBuilderMembers(io::Printer* printer) const { " }\n" " return $default$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n" " if (value == null) {\n" " throw new NullPointerException();\n" " }\n" @@ -460,9 +474,10 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " $clear_oneof_case_message$;\n" " $oneof_name$_ = null;\n" @@ -470,6 +485,7 @@ GenerateBuilderMembers(io::Printer* printer) const { " }\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableEnumOneofFieldGenerator:: @@ -502,12 +518,8 @@ GenerateParsingCode(io::Printer* printer) const { printer->Print(variables_, "int rawValue = input.readEnum();\n" "$type$ value = $type$.$for_number$(rawValue);\n" - "if (value == null) {\n"); - if (PreserveUnknownFields(descriptor_->containing_type())) { - printer->Print(variables_, - " unknownFields.mergeVarintField($number$, rawValue);\n"); - } - printer->Print(variables_, + "if (value == null) {\n" + " unknownFields.mergeVarintField($number$, rawValue);\n" "} else {\n" " $set_oneof_case_message$;\n" " $oneof_name$_ = rawValue;\n" @@ -621,32 +633,38 @@ GenerateMembers(io::Printer* printer) const { PrintExtraFieldInfo(variables_, printer); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n" + "$deprecation$public java.util.List<$type$> " + "${$get$capitalized_name$List$}$() {\n" " return new com.google.protobuf.Internal.ListAdapter<\n" " java.lang.Integer, $type$>($name$_, $name$_converter_);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return $name$_.size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$(int index) {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n" " return $name$_converter_.convert($name$_.get(index));\n" "}\n"); + printer->Annotate("{", "}", descriptor_); if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public java.util.List<java.lang.Integer>\n" - "get$capitalized_name$ValueList() {\n" + "${$get$capitalized_name$ValueList$}$() {\n" " return $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Value(int index) {\n" + "$deprecation$public int ${$get$capitalized_name$Value$}$(int index) {\n" " return $name$_.get(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } if (descriptor_->is_packed() && @@ -684,23 +702,27 @@ GenerateBuilderMembers(io::Printer* printer) const { // could hold on to the returned list and modify it after the message // has been built, thus mutating the message which is supposed to be // immutable. - "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n" + "$deprecation$public java.util.List<$type$> " + "${$get$capitalized_name$List$}$() {\n" " return new com.google.protobuf.Internal.ListAdapter<\n" " java.lang.Integer, $type$>($name$_, $name$_converter_);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return $name$_.size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$(int index) {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n" " return $name$_converter_.convert($name$_.get(index));\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value) {\n" " if (value == null) {\n" " throw new NullPointerException();\n" @@ -710,9 +732,10 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value) {\n" " if (value == null) {\n" " throw new NullPointerException();\n" " }\n" @@ -721,9 +744,10 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder addAll$capitalized_name$(\n" + "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<? extends $type$> values) {\n" " ensure$capitalized_name$IsMutable();\n" " for ($type$ value : values) {\n" @@ -732,47 +756,54 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " $name$_ = java.util.Collections.emptyList();\n" " $clear_mutable_bit_builder$;\n" " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public java.util.List<java.lang.Integer>\n" - "get$capitalized_name$ValueList() {\n" + "${$get$capitalized_name$ValueList$}$() {\n" " return java.util.Collections.unmodifiableList($name$_);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Value(int index) {\n" + "$deprecation$public int ${$get$capitalized_name$Value$}$(int index) {\n" " return $name$_.get(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$Value(\n" + "$deprecation$public Builder ${$set$capitalized_name$Value$}$(\n" " int index, int value) {\n" " ensure$capitalized_name$IsMutable();\n" " $name$_.set(index, value);\n" " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$Value(int value) {\n" + "$deprecation$public Builder " + "${$add$capitalized_name$Value$}$(int value) {\n" " ensure$capitalized_name$IsMutable();\n" " $name$_.add(value);\n" " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder addAll$capitalized_name$Value(\n" + "$deprecation$public Builder ${$addAll$capitalized_name$Value$}$(\n" " java.lang.Iterable<java.lang.Integer> values) {\n" " ensure$capitalized_name$IsMutable();\n" " for (int value : values) {\n" @@ -781,6 +812,7 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } } @@ -848,12 +880,8 @@ GenerateParsingCode(io::Printer* printer) const { printer->Print(variables_, "int rawValue = input.readEnum();\n" "$type$ value = $type$.$for_number$(rawValue);\n" - "if (value == null) {\n"); - if (PreserveUnknownFields(descriptor_->containing_type())) { - printer->Print(variables_, - " unknownFields.mergeVarintField($number$, rawValue);\n"); - } - printer->Print(variables_, + "if (value == null) {\n" + " unknownFields.mergeVarintField($number$, rawValue);\n" "} else {\n" " if (!$get_mutable_bit_parser$) {\n" " $name$_ = new java.util.ArrayList<java.lang.Integer>();\n" diff --git a/src/google/protobuf/compiler/java/java_enum_field_lite.cc b/src/google/protobuf/compiler/java/java_enum_field_lite.cc index 1eefdcfc..a4de1e23 100644 --- a/src/google/protobuf/compiler/java/java_enum_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_enum_field_lite.cc @@ -165,23 +165,26 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Value() {\n" + "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n" " return $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " $type$ result = $type$.forNumber($name$_);\n" " return result == null ? $unknown$ : result;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Generate private setters for the builder to proxy into. if (SupportUnknownEnumValue(descriptor_->file())) { @@ -214,43 +217,50 @@ GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return instance.has$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Value() {\n" + "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n" " return instance.get$capitalized_name$Value();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$Value(int value) {\n" + "$deprecation$public Builder " + "${$set$capitalized_name$Value$}$(int value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$Value(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableEnumFieldLiteGenerator:: @@ -296,12 +306,8 @@ GenerateParsingCode(io::Printer* printer) const { printer->Print(variables_, "int rawValue = input.readEnum();\n" "$type$ value = $type$.forNumber(rawValue);\n" - "if (value == null) {\n"); - if (PreserveUnknownFields(descriptor_->containing_type())) { - printer->Print(variables_, - " super.mergeVarintField($number$, rawValue);\n"); - } - printer->Print(variables_, + "if (value == null) {\n" + " super.mergeVarintField($number$, rawValue);\n" "} else {\n" " $set_has_field_bit_message$\n" " $name$_ = rawValue;\n" @@ -372,29 +378,32 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Value() {\n" + "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n" " if ($has_oneof_case_message$) {\n" " return (java.lang.Integer) $oneof_name$_;\n" " }\n" " return $default_number$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " $type$ result = $type$.forNumber((java.lang.Integer) $oneof_name$_);\n" " return result == null ? $unknown$ : result;\n" " }\n" " return $default$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Generate private setters for the builder to proxy into. if (SupportUnknownEnumValue(descriptor_->file())) { @@ -430,43 +439,50 @@ GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return instance.has$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Value() {\n" + "$deprecation$public int ${$get$capitalized_name$Value$}$() {\n" " return instance.get$capitalized_name$Value();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$Value(int value) {\n" + "$deprecation$public Builder " + "${$set$capitalized_name$Value$}$(int value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$Value(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableEnumOneofFieldLiteGenerator:: @@ -487,12 +503,8 @@ GenerateParsingCode(io::Printer* printer) const { printer->Print(variables_, "int rawValue = input.readEnum();\n" "$type$ value = $type$.forNumber(rawValue);\n" - "if (value == null) {\n"); - if (PreserveUnknownFields(descriptor_->containing_type())) { - printer->Print(variables_, - " super.mergeVarintField($number$, rawValue);\n"); - } - printer->Print(variables_, + "if (value == null) {\n" + " super.mergeVarintField($number$, rawValue);\n" "} else {\n" " $set_oneof_case_message$;\n" " $oneof_name$_ = rawValue;\n" @@ -607,35 +619,41 @@ GenerateMembers(io::Printer* printer) const { PrintExtraFieldInfo(variables_, printer); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n" + "$deprecation$public java.util.List<$type$> " + "${$get$capitalized_name$List$}$() {\n" " return new com.google.protobuf.Internal.ListAdapter<\n" " java.lang.Integer, $type$>($name$_, $name$_converter_);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return $name$_.size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$(int index) {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n" " return $name$_converter_.convert($name$_.getInt(index));\n" "}\n"); + printer->Annotate("{", "}", descriptor_); if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public java.util.List<java.lang.Integer>\n" - "get$capitalized_name$ValueList() {\n" + "${$get$capitalized_name$ValueList$}$() {\n" " return $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Value(int index) {\n" + "$deprecation$public int ${$get$capitalized_name$Value$}$(int index) {\n" " return $name$_.getInt(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } - if (descriptor_->options().packed() && + if (descriptor_->is_packed() && context_->HasGeneratedMethods(descriptor_->containing_type())) { printer->Print(variables_, "private int $name$MemoizedSerializedSize;\n"); @@ -714,85 +732,99 @@ void RepeatedImmutableEnumFieldLiteGenerator:: GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n" + "$deprecation$public java.util.List<$type$> " + "${$get$capitalized_name$List$}$() {\n" " return instance.get$capitalized_name$List();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return instance.get$capitalized_name$Count();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$(int index) {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n" " return instance.get$capitalized_name$(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(index, value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" " instance.add$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder addAll$capitalized_name$(\n" + "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<? extends $type$> values) {\n" " copyOnWrite();\n" " instance.addAll$capitalized_name$(values);" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); if (SupportUnknownEnumValue(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public java.util.List<java.lang.Integer>\n" - "get$capitalized_name$ValueList() {\n" + "${$get$capitalized_name$ValueList$}$() {\n" " return java.util.Collections.unmodifiableList(\n" " instance.get$capitalized_name$ValueList());\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Value(int index) {\n" + "$deprecation$public int ${$get$capitalized_name$Value$}$(int index) {\n" " return instance.get$capitalized_name$Value(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$Value(\n" + "$deprecation$public Builder ${$set$capitalized_name$Value$}$(\n" " int index, int value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$Value(index, value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$Value(int value) {\n" + "$deprecation$public Builder " + "${$add$capitalized_name$Value$}$(int value) {\n" " instance.add$capitalized_name$Value(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder addAll$capitalized_name$Value(\n" + "$deprecation$public Builder ${$addAll$capitalized_name$Value$}$(\n" " java.lang.Iterable<java.lang.Integer> values) {\n" " copyOnWrite();\n" " instance.addAll$capitalized_name$Value(values);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } } @@ -889,7 +921,7 @@ GenerateParsingDoneCode(io::Printer* printer) const { void RepeatedImmutableEnumFieldLiteGenerator:: GenerateSerializationCode(io::Printer* printer) const { - if (descriptor_->options().packed()) { + if (descriptor_->is_packed()) { printer->Print(variables_, "if (get$capitalized_name$List().size() > 0) {\n" " output.writeUInt32NoTag($tag$);\n" @@ -920,7 +952,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const { "}\n"); printer->Print( "size += dataSize;\n"); - if (descriptor_->options().packed()) { + if (descriptor_->is_packed()) { printer->Print(variables_, "if (!get$capitalized_name$List().isEmpty()) {" " size += $tag_size$;\n" @@ -933,7 +965,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const { } // cache the data size for packed fields. - if (descriptor_->options().packed()) { + if (descriptor_->is_packed()) { printer->Print(variables_, "$name$MemoizedSerializedSize = dataSize;\n"); } diff --git a/src/google/protobuf/compiler/java/java_enum_lite.cc b/src/google/protobuf/compiler/java/java_enum_lite.cc index 38b054e7..ab3b3323 100644 --- a/src/google/protobuf/compiler/java/java_enum_lite.cc +++ b/src/google/protobuf/compiler/java/java_enum_lite.cc @@ -93,10 +93,12 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { } printer->Print(vars, "$name$($number$),\n"); + printer->Annotate("name", canonical_values_[i]); } if (SupportUnknownEnumValue(descriptor_->file())) { - printer->Print("UNRECOGNIZED(-1),\n"); + printer->Print("${$UNRECOGNIZED$}$(-1),\n", "{", "", "}", ""); + printer->Annotate("{", "}", descriptor_); } printer->Print( @@ -113,15 +115,19 @@ void EnumLiteGenerator::Generate(io::Printer* printer) { WriteEnumValueDocComment(printer, aliases_[i].value); printer->Print(vars, "public static final $classname$ $name$ = $canonical_name$;\n"); + printer->Annotate("name", aliases_[i].value); } for (int i = 0; i < descriptor_->value_count(); i++) { std::map<string, string> vars; vars["name"] = descriptor_->value(i)->name(); vars["number"] = SimpleItoa(descriptor_->value(i)->number()); + vars["{"] = ""; + vars["}"] = ""; WriteEnumValueDocComment(printer, descriptor_->value(i)); printer->Print(vars, - "public static final int $name$_VALUE = $number$;\n"); + "public static final int ${$$name$_VALUE$}$ = $number$;\n"); + printer->Annotate("{", "}", descriptor_->value(i)); } printer->Print("\n"); diff --git a/src/google/protobuf/compiler/java/java_extension.cc b/src/google/protobuf/compiler/java/java_extension.cc index cb237bf6..9b9be55b 100644 --- a/src/google/protobuf/compiler/java/java_extension.cc +++ b/src/google/protobuf/compiler/java/java_extension.cc @@ -75,7 +75,7 @@ void ExtensionGenerator::InitTemplateVars( vars["default"] = descriptor->is_repeated() ? "" : DefaultValue(descriptor, immutable, name_resolver); vars["type_constant"] = FieldTypeName(GetType(descriptor)); - vars["packed"] = descriptor->options().packed() ? "true" : "false"; + vars["packed"] = descriptor->is_packed() ? "true" : "false"; vars["enum_map"] = "null"; vars["prototype"] = "null"; diff --git a/src/google/protobuf/compiler/java/java_field.cc b/src/google/protobuf/compiler/java/java_field.cc index 04917296..1ab18629 100644 --- a/src/google/protobuf/compiler/java/java_field.cc +++ b/src/google/protobuf/compiler/java/java_field.cc @@ -45,8 +45,6 @@ #include <google/protobuf/compiler/java/java_enum_field.h> #include <google/protobuf/compiler/java/java_enum_field_lite.h> #include <google/protobuf/compiler/java/java_helpers.h> -#include <google/protobuf/compiler/java/java_lazy_message_field.h> -#include <google/protobuf/compiler/java/java_lazy_message_field_lite.h> #include <google/protobuf/compiler/java/java_map_field.h> #include <google/protobuf/compiler/java/java_map_field_lite.h> #include <google/protobuf/compiler/java/java_message_field.h> @@ -77,13 +75,8 @@ ImmutableFieldGenerator* MakeImmutableGenerator( return new ImmutableMapFieldGenerator( field, messageBitIndex, builderBitIndex, context); } else { - if (IsLazy(field, context->EnforceLite())) { - return new RepeatedImmutableLazyMessageFieldGenerator( - field, messageBitIndex, builderBitIndex, context); - } else { - return new RepeatedImmutableMessageFieldGenerator( - field, messageBitIndex, builderBitIndex, context); - } + return new RepeatedImmutableMessageFieldGenerator( + field, messageBitIndex, builderBitIndex, context); } case JAVATYPE_ENUM: return new RepeatedImmutableEnumFieldGenerator( @@ -99,13 +92,8 @@ ImmutableFieldGenerator* MakeImmutableGenerator( if (field->containing_oneof()) { switch (GetJavaType(field)) { case JAVATYPE_MESSAGE: - if (IsLazy(field, context->EnforceLite())) { - return new ImmutableLazyMessageOneofFieldGenerator( - field, messageBitIndex, builderBitIndex, context); - } else { - return new ImmutableMessageOneofFieldGenerator( - field, messageBitIndex, builderBitIndex, context); - } + return new ImmutableMessageOneofFieldGenerator( + field, messageBitIndex, builderBitIndex, context); case JAVATYPE_ENUM: return new ImmutableEnumOneofFieldGenerator( field, messageBitIndex, builderBitIndex, context); @@ -119,13 +107,8 @@ ImmutableFieldGenerator* MakeImmutableGenerator( } else { switch (GetJavaType(field)) { case JAVATYPE_MESSAGE: - if (IsLazy(field, context->EnforceLite())) { - return new ImmutableLazyMessageFieldGenerator( - field, messageBitIndex, builderBitIndex, context); - } else { - return new ImmutableMessageFieldGenerator( - field, messageBitIndex, builderBitIndex, context); - } + return new ImmutableMessageFieldGenerator( + field, messageBitIndex, builderBitIndex, context); case JAVATYPE_ENUM: return new ImmutableEnumFieldGenerator( field, messageBitIndex, builderBitIndex, context); @@ -150,13 +133,8 @@ ImmutableFieldLiteGenerator* MakeImmutableLiteGenerator( return new ImmutableMapFieldLiteGenerator( field, messageBitIndex, builderBitIndex, context); } else { - if (IsLazy(field, context->EnforceLite())) { - return new RepeatedImmutableLazyMessageFieldLiteGenerator( - field, messageBitIndex, builderBitIndex, context); - } else { - return new RepeatedImmutableMessageFieldLiteGenerator( - field, messageBitIndex, builderBitIndex, context); - } + return new RepeatedImmutableMessageFieldLiteGenerator( + field, messageBitIndex, builderBitIndex, context); } case JAVATYPE_ENUM: return new RepeatedImmutableEnumFieldLiteGenerator( @@ -172,13 +150,8 @@ ImmutableFieldLiteGenerator* MakeImmutableLiteGenerator( if (field->containing_oneof()) { switch (GetJavaType(field)) { case JAVATYPE_MESSAGE: - if (IsLazy(field, context->EnforceLite())) { - return new ImmutableLazyMessageOneofFieldLiteGenerator( - field, messageBitIndex, builderBitIndex, context); - } else { - return new ImmutableMessageOneofFieldLiteGenerator( - field, messageBitIndex, builderBitIndex, context); - } + return new ImmutableMessageOneofFieldLiteGenerator( + field, messageBitIndex, builderBitIndex, context); case JAVATYPE_ENUM: return new ImmutableEnumOneofFieldLiteGenerator( field, messageBitIndex, builderBitIndex, context); @@ -192,13 +165,8 @@ ImmutableFieldLiteGenerator* MakeImmutableLiteGenerator( } else { switch (GetJavaType(field)) { case JAVATYPE_MESSAGE: - if (IsLazy(field, context->EnforceLite())) { - return new ImmutableLazyMessageFieldLiteGenerator( - field, messageBitIndex, builderBitIndex, context); - } else { - return new ImmutableMessageFieldLiteGenerator( - field, messageBitIndex, builderBitIndex, context); - } + return new ImmutableMessageFieldLiteGenerator( + field, messageBitIndex, builderBitIndex, context); case JAVATYPE_ENUM: return new ImmutableEnumFieldLiteGenerator( field, messageBitIndex, builderBitIndex, context); @@ -293,10 +261,17 @@ void SetCommonFieldVariables(const FieldDescriptor* descriptor, std::map<string, string>* variables) { (*variables)["field_name"] = descriptor->name(); (*variables)["name"] = info->name; + (*variables)["classname"] = descriptor->containing_type()->name(); (*variables)["capitalized_name"] = info->capitalized_name; (*variables)["disambiguated_reason"] = info->disambiguated_reason; (*variables)["constant_name"] = FieldConstantName(descriptor); (*variables)["number"] = SimpleItoa(descriptor->number()); + // These variables are placeholders to pick out the beginning and ends of + // identifiers for annotations (when doing so with existing variables would + // be ambiguous or impossible). They should never be set to anything but the + // empty string. + (*variables)["{"] = ""; + (*variables)["}"] = ""; } void SetCommonOneofVariables(const FieldDescriptor* descriptor, diff --git a/src/google/protobuf/compiler/java/java_file.cc b/src/google/protobuf/compiler/java/java_file.cc index 0fda166d..2d5465ba 100644 --- a/src/google/protobuf/compiler/java/java_file.cc +++ b/src/google/protobuf/compiler/java/java_file.cc @@ -499,19 +499,57 @@ void FileGenerator::GenerateDescriptorInitializationCodeForMutable(io::Printer* // Try to load immutable messages' outer class. Its initialization code // will take care of interpreting custom options. printer->Print( - "try {\n" - // Note that we have to load the immutable class dynamically here as - // we want the mutable code to be independent from the immutable code - // at compile time. It is required to implement dual-compile for - // mutable and immutable API in blaze. - " java.lang.Class immutableClass = java.lang.Class.forName(\n" - " \"$immutable_classname$\");\n" - "} catch (java.lang.ClassNotFoundException e) {\n" - // The immutable class can not be found. Custom options are left - // as unknown fields. - // TODO(xiaofeng): inform the user with a warning? - "}\n", - "immutable_classname", name_resolver_->GetImmutableClassName(file_)); + "try {\n" + // Note that we have to load the immutable class dynamically here as + // we want the mutable code to be independent from the immutable code + // at compile time. It is required to implement dual-compile for + // mutable and immutable API in blaze. + " java.lang.Class immutableClass = java.lang.Class.forName(\n" + " \"$immutable_classname$\");\n" + "} catch (java.lang.ClassNotFoundException e) {\n", + "immutable_classname", name_resolver_->GetImmutableClassName(file_)); + printer->Indent(); + + // The immutable class can not be found. We try our best to collect all + // custom option extensions to interpret the custom options. + printer->Print( + "com.google.protobuf.ExtensionRegistry registry =\n" + " com.google.protobuf.ExtensionRegistry.newInstance();\n" + "com.google.protobuf.MessageLite defaultExtensionInstance = null;\n"); + FieldDescriptorSet::iterator it; + for (it = extensions.begin(); it != extensions.end(); it++) { + const FieldDescriptor* field = *it; + string scope; + if (field->extension_scope() != NULL) { + scope = name_resolver_->GetMutableClassName(field->extension_scope()) + + ".getDescriptor()"; + } else { + scope = FileJavaPackage(field->file(), true) + "." + + name_resolver_->GetDescriptorClassName(field->file()) + + ".descriptor"; + } + if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { + printer->Print( + "defaultExtensionInstance = com.google.protobuf.Internal\n" + " .getDefaultInstance(\"$class$\");\n" + "if (defaultExtensionInstance != null) {\n" + " registry.add(\n" + " $scope$.getExtensions().get($index$),\n" + " (com.google.protobuf.Message) defaultExtensionInstance);\n" + "}\n", + "scope", scope, "index", SimpleItoa(field->index()), "class", + name_resolver_->GetImmutableClassName(field->message_type())); + } else { + printer->Print("registry.add($scope$.getExtensions().get($index$));\n", + "scope", scope, "index", SimpleItoa(field->index())); + } + } + printer->Print( + "com.google.protobuf.Descriptors.FileDescriptor\n" + " .internalUpdateFileDescriptor(descriptor, registry);\n"); + + printer->Outdent(); + printer->Print("}\n"); } // Force descriptor initialization of all dependencies. diff --git a/src/google/protobuf/compiler/java/java_generator.cc b/src/google/protobuf/compiler/java/java_generator.cc index 02141210..84a3b90d 100644 --- a/src/google/protobuf/compiler/java/java_generator.cc +++ b/src/google/protobuf/compiler/java/java_generator.cc @@ -42,6 +42,7 @@ #include <google/protobuf/compiler/java/java_file.h> #include <google/protobuf/compiler/java/java_generator_factory.h> #include <google/protobuf/compiler/java/java_helpers.h> +#include <google/protobuf/compiler/java/java_name_resolver.h> #include <google/protobuf/compiler/java/java_options.h> #include <google/protobuf/compiler/java/java_shared_code_generator.h> #include <google/protobuf/io/printer.h> diff --git a/src/google/protobuf/compiler/java/java_helpers.cc b/src/google/protobuf/compiler/java/java_helpers.cc index 8469740f..d8ac2db3 100644 --- a/src/google/protobuf/compiler/java/java_helpers.cc +++ b/src/google/protobuf/compiler/java/java_helpers.cc @@ -43,6 +43,8 @@ #include <google/protobuf/wire_format.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> + + #include <google/protobuf/stubs/hash.h> // for hash<T *> namespace google { @@ -167,6 +169,14 @@ string UniqueFileScopeIdentifier(const Descriptor* descriptor) { return "static_" + StringReplace(descriptor->full_name(), ".", "_", true); } +string CamelCaseFieldName(const FieldDescriptor* field) { + string fieldName = UnderscoresToCamelCase(field); + if ('0' <= fieldName[0] && fieldName[0] <= '9') { + return '_' + fieldName; + } + return fieldName; +} + string StripProto(const string& filename) { if (HasSuffixString(filename, ".protodevel")) { return StripSuffixString(filename, ".protodevel"); diff --git a/src/google/protobuf/compiler/java/java_helpers.h b/src/google/protobuf/compiler/java/java_helpers.h index 829ec3d7..bd565ced 100644 --- a/src/google/protobuf/compiler/java/java_helpers.h +++ b/src/google/protobuf/compiler/java/java_helpers.h @@ -74,6 +74,10 @@ string UnderscoresToCapitalizedCamelCase(const FieldDescriptor* field); // of lower-casing the first letter of the name.) string UnderscoresToCamelCase(const MethodDescriptor* method); +// Similar to UnderscoresToCamelCase, but guarentees that the result is a +// complete Java identifier by adding a _ if needed. +string CamelCaseFieldName(const FieldDescriptor* field); + // Get an identifier that uniquely identifies this type within the file. // This is used to declare static variables related to this type at the // outermost file scope. @@ -242,15 +246,6 @@ inline bool HasGenericServices(const FileDescriptor *file, bool enforce_lite) { file->options().java_generic_services(); } -inline bool IsLazy(const FieldDescriptor* descriptor, bool enforce_lite) { - // Currently, the proto-lite version supports lazy field. - // TODO(niwasaki): Support lazy fields also for other proto runtimes. - if (HasDescriptorMethods(descriptor->file(), enforce_lite)) { - return false; - } - return descriptor->options().lazy(); -} - // Methods for shared bitfields. // Gets the name of the shared bitfield for the given index. @@ -372,10 +367,6 @@ inline bool IsMapField(const FieldDescriptor* descriptor) { return descriptor->is_map(); } -inline bool PreserveUnknownFields(const Descriptor* descriptor) { - return descriptor->file()->syntax() != FileDescriptor::SYNTAX_PROTO3; -} - inline bool IsAnyMessage(const Descriptor* descriptor) { return descriptor->full_name() == "google.protobuf.Any"; } diff --git a/src/google/protobuf/compiler/java/java_map_field.cc b/src/google/protobuf/compiler/java/java_map_field.cc index 608b5378..b22a2199 100644 --- a/src/google/protobuf/compiler/java/java_map_field.cc +++ b/src/google/protobuf/compiler/java/java_map_field.cc @@ -183,12 +183,14 @@ GenerateInterfaceMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$int get$capitalized_name$Count();\n"); + "$deprecation$int ${$get$capitalized_name$Count$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$boolean contains$capitalized_name$(\n" + "$deprecation$boolean ${$contains$capitalized_name$$}$(\n" " $key_type$ key);\n"); + printer->Annotate("{", "}", descriptor_); if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { printer->Print( variables_, @@ -197,23 +199,27 @@ GenerateInterfaceMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "get$capitalized_name$();\n"); + "${$get$capitalized_name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "get$capitalized_name$Map();\n"); + "${$get$capitalized_name$Map$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$$value_enum_type$ get$capitalized_name$OrDefault(\n" + "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_enum_type$ defaultValue);\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$$value_enum_type$ get$capitalized_name$OrThrow(\n" + "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key);\n"); + printer->Annotate("{", "}", descriptor_); if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print( variables_, @@ -222,25 +228,29 @@ GenerateInterfaceMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "java.util.Map<$type_parameters$>\n" - "get$capitalized_name$Value();\n"); + "${$get$capitalized_name$Value$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$java.util.Map<$type_parameters$>\n" - "get$capitalized_name$ValueMap();\n"); + "${$get$capitalized_name$ValueMap$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "$value_type$ get$capitalized_name$ValueOrDefault(\n" + "$value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue);\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "$value_type$ get$capitalized_name$ValueOrThrow(\n" + "$value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" " $key_type$ key);\n"); + printer->Annotate("{", "}", descriptor_); } } else { printer->Print( @@ -250,25 +260,29 @@ GenerateInterfaceMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "java.util.Map<$type_parameters$>\n" - "get$capitalized_name$();\n"); + "${$get$capitalized_name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$java.util.Map<$type_parameters$>\n" - "get$capitalized_name$Map();\n"); + "${$get$capitalized_name$Map$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "$value_type$ get$capitalized_name$OrDefault(\n" + "$value_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue);\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "$value_type$ get$capitalized_name$OrThrow(\n" + "$value_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key);\n"); + printer->Annotate("{", "}", descriptor_); } } @@ -349,23 +363,27 @@ GenerateBuilderMembers(io::Printer* printer) const { " return $name$_;\n" "}\n"); GenerateMapGetters(printer); - printer->Print(variables_, - "$deprecation$\n" - "public Builder clear$capitalized_name$() {\n" - " internalGetMutable$capitalized_name$().getMutableMap()\n" - " .clear();\n" - " return this;\n" - "}\n"); + printer->Print( + variables_, + "$deprecation$\n" + "public Builder ${$clear$capitalized_name$$}$() {\n" + " internalGetMutable$capitalized_name$().getMutableMap()\n" + " .clear();\n" + " return this;\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$\n" - "public Builder remove$capitalized_name$(\n" - " $key_type$ key) {\n" - " $key_null_check$\n" - " internalGetMutable$capitalized_name$().getMutableMap()\n" - " .remove(key);\n" - " return this;\n" - "}\n"); + printer->Print( + variables_, + "$deprecation$\n" + "public Builder ${$remove$capitalized_name$$}$(\n" + " $key_type$ key) {\n" + " $key_null_check$\n" + " internalGetMutable$capitalized_name$().getMutableMap()\n" + " .remove(key);\n" + " return this;\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { printer->Print( variables_, @@ -374,13 +392,14 @@ GenerateBuilderMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "getMutable$capitalized_name$() {\n" + "${$getMutable$capitalized_name$$}$() {\n" " return internalGetAdapted$capitalized_name$Map(\n" " internalGetMutable$capitalized_name$().getMutableMap());\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder put$capitalized_name$(\n" + "$deprecation$public Builder ${$put$capitalized_name$$}$(\n" " $key_type$ key,\n" " $value_enum_type$ value) {\n" " $key_null_check$\n" @@ -389,16 +408,18 @@ GenerateBuilderMembers(io::Printer* printer) const { " .put(key, $name$ValueConverter.doBackward(value));\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$public Builder putAll$capitalized_name$(\n" + "$deprecation$public Builder ${$putAll$capitalized_name$$}$(\n" " java.util.Map<$boxed_key_type$, $value_enum_type$> values) {\n" " internalGetAdapted$capitalized_name$Map(\n" " internalGetMutable$capitalized_name$().getMutableMap())\n" " .putAll(values);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print( variables_, @@ -407,13 +428,14 @@ GenerateBuilderMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" - "getMutable$capitalized_name$Value() {\n" + "${$getMutable$capitalized_name$Value$}$() {\n" " return internalGetMutable$capitalized_name$().getMutableMap();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$public Builder put$capitalized_name$Value(\n" + "$deprecation$public Builder ${$put$capitalized_name$Value$}$(\n" " $key_type$ key,\n" " $value_type$ value) {\n" " $key_null_check$\n" @@ -421,15 +443,17 @@ GenerateBuilderMembers(io::Printer* printer) const { " .put(key, value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$public Builder putAll$capitalized_name$Value(\n" + "$deprecation$public Builder ${$putAll$capitalized_name$Value$}$(\n" " java.util.Map<$boxed_key_type$, $boxed_value_type$> values) {\n" " internalGetMutable$capitalized_name$().getMutableMap()\n" " .putAll(values);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } } else { printer->Print( @@ -439,30 +463,35 @@ GenerateBuilderMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "public java.util.Map<$type_parameters$>\n" - "getMutable$capitalized_name$() {\n" + "${$getMutable$capitalized_name$$}$() {\n" " return internalGetMutable$capitalized_name$().getMutableMap();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$" - "public Builder put$capitalized_name$(\n" - " $key_type$ key,\n" - " $value_type$ value) {\n" - " $key_null_check$\n" - " $value_null_check$\n" - " internalGetMutable$capitalized_name$().getMutableMap()\n" - " .put(key, value);\n" - " return this;\n" - "}\n"); + printer->Print( + variables_, + "$deprecation$" + "public Builder ${$put$capitalized_name$$}$(\n" + " $key_type$ key,\n" + " $value_type$ value) {\n" + " $key_null_check$\n" + " $value_null_check$\n" + " internalGetMutable$capitalized_name$().getMutableMap()\n" + " .put(key, value);\n" + " return this;\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$\n" - "public Builder putAll$capitalized_name$(\n" - " java.util.Map<$type_parameters$> values) {\n" - " internalGetMutable$capitalized_name$().getMutableMap()\n" - " .putAll(values);\n" - " return this;\n" - "}\n"); + printer->Print( + variables_, + "$deprecation$\n" + "public Builder ${$putAll$capitalized_name$$}$(\n" + " java.util.Map<$type_parameters$> values) {\n" + " internalGetMutable$capitalized_name$().getMutableMap()\n" + " .putAll(values);\n" + " return this;\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); } } @@ -471,18 +500,20 @@ GenerateMapGetters(io::Printer* printer) const { printer->Print( variables_, "$deprecation$\n" - "public int get$capitalized_name$Count() {\n" + "public int ${$get$capitalized_name$Count$}$() {\n" " return internalGet$capitalized_name$().getMap().size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public boolean contains$capitalized_name$(\n" + "public boolean ${$contains$capitalized_name$$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " return internalGet$capitalized_name$().getMap().containsKey(key);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { printer->Print( variables_, @@ -491,22 +522,25 @@ GenerateMapGetters(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "get$capitalized_name$() {\n" + "${$get$capitalized_name$$}$() {\n" " return get$capitalized_name$Map();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$\n" - "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "get$capitalized_name$Map() {\n" - " return internalGetAdapted$capitalized_name$Map(\n" - " internalGet$capitalized_name$().getMap());" - "}\n"); + printer->Print( + variables_, + "$deprecation$\n" + "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" + "${$get$capitalized_name$Map$}$() {\n" + " return internalGetAdapted$capitalized_name$Map(\n" + " internalGet$capitalized_name$().getMap());" + "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_enum_type$ get$capitalized_name$OrDefault(\n" + "public $value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_enum_type$ defaultValue) {\n" " $key_null_check$\n" @@ -516,11 +550,12 @@ GenerateMapGetters(io::Printer* printer) const { " ? $name$ValueConverter.doForward(map.get(key))\n" " : defaultValue;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_enum_type$ get$capitalized_name$OrThrow(\n" + "public $value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" @@ -530,6 +565,7 @@ GenerateMapGetters(io::Printer* printer) const { " }\n" " return $name$ValueConverter.doForward(map.get(key));\n" "}\n"); + printer->Annotate("{", "}", descriptor_); if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print( variables_, @@ -538,22 +574,24 @@ GenerateMapGetters(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" - "get$capitalized_name$Value() {\n" + "${$get$capitalized_name$Value$}$() {\n" " return get$capitalized_name$ValueMap();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" - "get$capitalized_name$ValueMap() {\n" + "${$get$capitalized_name$ValueMap$}$() {\n" " return internalGet$capitalized_name$().getMap();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_type$ get$capitalized_name$ValueOrDefault(\n" + "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue) {\n" " $key_null_check$\n" @@ -561,11 +599,12 @@ GenerateMapGetters(io::Printer* printer) const { " internalGet$capitalized_name$().getMap();\n" " return map.containsKey(key) ? map.get(key) : defaultValue;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_type$ get$capitalized_name$ValueOrThrow(\n" + "public $value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" @@ -575,6 +614,7 @@ GenerateMapGetters(io::Printer* printer) const { " }\n" " return map.get(key);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } } else { printer->Print( @@ -583,21 +623,25 @@ GenerateMapGetters(io::Printer* printer) const { " * Use {@link #get$capitalized_name$Map()} instead.\n" " */\n" "@java.lang.Deprecated\n" - "public java.util.Map<$type_parameters$> get$capitalized_name$() {\n" + "public java.util.Map<$type_parameters$> " + "${$get$capitalized_name$$}$() {\n" " return get$capitalized_name$Map();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public java.util.Map<$type_parameters$> get$capitalized_name$Map() {\n" + "public java.util.Map<$type_parameters$> " + "${$get$capitalized_name$Map$}$() {\n" " return internalGet$capitalized_name$().getMap();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_type$ get$capitalized_name$OrDefault(\n" + "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue) {\n" " $key_null_check$\n" @@ -605,11 +649,12 @@ GenerateMapGetters(io::Printer* printer) const { " internalGet$capitalized_name$().getMap();\n" " return map.containsKey(key) ? map.get(key) : defaultValue;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_type$ get$capitalized_name$OrThrow(\n" + "public $value_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " java.util.Map<$type_parameters$> map =\n" @@ -619,6 +664,7 @@ GenerateMapGetters(io::Printer* printer) const { " }\n" " return map.get(key);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } } diff --git a/src/google/protobuf/compiler/java/java_map_field_lite.cc b/src/google/protobuf/compiler/java/java_map_field_lite.cc index 073d1cfc..f19ec271 100644 --- a/src/google/protobuf/compiler/java/java_map_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_map_field_lite.cc @@ -166,12 +166,14 @@ GenerateInterfaceMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$int get$capitalized_name$Count();\n"); + "$deprecation$int ${$get$capitalized_name$Count$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$boolean contains$capitalized_name$(\n" + "$deprecation$boolean ${$contains$capitalized_name$$}$(\n" " $key_type$ key);\n"); + printer->Annotate("{", "}", descriptor_); if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { printer->Print( variables_, @@ -180,23 +182,27 @@ GenerateInterfaceMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "get$capitalized_name$();\n"); + "${$get$capitalized_name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "get$capitalized_name$Map();\n"); + "${$get$capitalized_name$Map$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$$value_enum_type$ get$capitalized_name$OrDefault(\n" + "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_enum_type$ defaultValue);\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$$value_enum_type$ get$capitalized_name$OrThrow(\n" + "$deprecation$$value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key);\n"); + printer->Annotate("{", "}", descriptor_); if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print( variables_, @@ -205,25 +211,29 @@ GenerateInterfaceMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "java.util.Map<$type_parameters$>\n" - "get$capitalized_name$Value();\n"); + "${$get$capitalized_name$Value$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$java.util.Map<$type_parameters$>\n" - "get$capitalized_name$ValueMap();\n"); + "${$get$capitalized_name$ValueMap$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "$value_type$ get$capitalized_name$ValueOrDefault(\n" + "$value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue);\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "$value_type$ get$capitalized_name$ValueOrThrow(\n" + "$value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" " $key_type$ key);\n"); + printer->Annotate("{", "}", descriptor_); } } else { printer->Print( @@ -233,25 +243,29 @@ GenerateInterfaceMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "java.util.Map<$type_parameters$>\n" - "get$capitalized_name$();\n"); + "${$get$capitalized_name$$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$java.util.Map<$type_parameters$>\n" - "get$capitalized_name$Map();\n"); + "${$get$capitalized_name$Map$}$();\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "$value_type$ get$capitalized_name$OrDefault(\n" + "$value_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue);\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "$value_type$ get$capitalized_name$OrThrow(\n" + "$value_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key);\n"); + printer->Annotate("{", "}", descriptor_); } } @@ -288,18 +302,20 @@ GenerateMembers(io::Printer* printer) const { printer->Print( variables_, "$deprecation$\n" - "public int get$capitalized_name$Count() {\n" + "public int ${$get$capitalized_name$Count$}$() {\n" " return internalGet$capitalized_name$().size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public boolean contains$capitalized_name$(\n" + "public boolean ${$contains$capitalized_name$$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " return internalGet$capitalized_name$().containsKey(key);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { printer->Print( variables_, @@ -316,26 +332,28 @@ GenerateMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "get$capitalized_name$() {\n" + "${$get$capitalized_name$$}$() {\n" " return get$capitalized_name$Map();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "get$capitalized_name$Map() {\n" + "${$get$capitalized_name$Map$}$() {\n" " return java.util.Collections.unmodifiableMap(\n" " new com.google.protobuf.Internal.MapAdapter<\n" " $boxed_key_type$, $value_enum_type$, java.lang.Integer>(\n" " internalGet$capitalized_name$(),\n" " $name$ValueConverter));\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_enum_type$ get$capitalized_name$OrDefault(\n" + "public $value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_enum_type$ defaultValue) {\n" " $key_null_check$\n" @@ -345,11 +363,12 @@ GenerateMembers(io::Printer* printer) const { " ? $name$ValueConverter.doForward(map.get(key))\n" " : defaultValue;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_enum_type$ get$capitalized_name$OrThrow(\n" + "public $value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" @@ -359,6 +378,7 @@ GenerateMembers(io::Printer* printer) const { " }\n" " return $name$ValueConverter.doForward(map.get(key));\n" "}\n"); + printer->Annotate("{", "}", descriptor_); if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print( variables_, @@ -367,23 +387,25 @@ GenerateMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" - "get$capitalized_name$Value() {\n" + "${$get$capitalized_name$Value$}$() {\n" " return get$capitalized_name$ValueMap();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" - "get$capitalized_name$ValueMap() {\n" + "${$get$capitalized_name$ValueMap$}$() {\n" " return java.util.Collections.unmodifiableMap(\n" " internalGet$capitalized_name$());\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_type$ get$capitalized_name$ValueOrDefault(\n" + "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue) {\n" " $key_null_check$\n" @@ -391,11 +413,12 @@ GenerateMembers(io::Printer* printer) const { " internalGet$capitalized_name$();\n" " return map.containsKey(key) ? map.get(key) : defaultValue;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_type$ get$capitalized_name$ValueOrThrow(\n" + "public $value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" @@ -405,6 +428,7 @@ GenerateMembers(io::Printer* printer) const { " }\n" " return map.get(key);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } } else { printer->Print( @@ -413,22 +437,26 @@ GenerateMembers(io::Printer* printer) const { " * Use {@link #get$capitalized_name$Map()} instead.\n" " */\n" "@java.lang.Deprecated\n" - "public java.util.Map<$type_parameters$> get$capitalized_name$() {\n" + "public java.util.Map<$type_parameters$> " + "${$get$capitalized_name$$}$() {\n" " return get$capitalized_name$Map();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public java.util.Map<$type_parameters$> get$capitalized_name$Map() {\n" + "public java.util.Map<$type_parameters$> " + "${$get$capitalized_name$Map$}$() {\n" " return java.util.Collections.unmodifiableMap(\n" " internalGet$capitalized_name$());\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_type$ get$capitalized_name$OrDefault(\n" + "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue) {\n" " $key_null_check$\n" @@ -436,11 +464,12 @@ GenerateMembers(io::Printer* printer) const { " internalGet$capitalized_name$();\n" " return map.containsKey(key) ? map.get(key) : defaultValue;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_type$ get$capitalized_name$OrThrow(\n" + "public $value_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " java.util.Map<$type_parameters$> map =\n" @@ -450,6 +479,7 @@ GenerateMembers(io::Printer* printer) const { " }\n" " return map.get(key);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } // Generate private setters for the builder to proxy into. @@ -490,37 +520,41 @@ GenerateBuilderMembers(io::Printer* printer) const { printer->Print( variables_, "$deprecation$\n" - "public int get$capitalized_name$Count() {\n" + "public int ${$get$capitalized_name$Count$}$() {\n" " return instance.get$capitalized_name$Map().size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public boolean contains$capitalized_name$(\n" + "public boolean ${$contains$capitalized_name$$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " return instance.get$capitalized_name$Map().containsKey(key);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); printer->Print( variables_, "$deprecation$\n" - "public Builder clear$capitalized_name$() {\n" + "public Builder ${$clear$capitalized_name$$}$() {\n" " copyOnWrite();\n" " instance.getMutable$capitalized_name$Map().clear();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public Builder remove$capitalized_name$(\n" + "public Builder ${$remove$capitalized_name$$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " copyOnWrite();\n" " instance.getMutable$capitalized_name$Map().remove(key);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); if (GetJavaType(ValueField(descriptor_)) == JAVATYPE_ENUM) { printer->Print( variables_, @@ -529,23 +563,25 @@ GenerateBuilderMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "get$capitalized_name$() {\n" + "${$get$capitalized_name$$}$() {\n" " return get$capitalized_name$Map();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" "public java.util.Map<$boxed_key_type$, $value_enum_type$>\n" - "get$capitalized_name$Map() {\n" + "${$get$capitalized_name$Map$}$() {\n" " return java.util.Collections.unmodifiableMap(\n" " instance.get$capitalized_name$Map());\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_enum_type$ get$capitalized_name$OrDefault(\n" + "public $value_enum_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_enum_type$ defaultValue) {\n" " $key_null_check$\n" @@ -555,11 +591,12 @@ GenerateBuilderMembers(io::Printer* printer) const { " ? map.get(key)\n" " : defaultValue;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_enum_type$ get$capitalized_name$OrThrow(\n" + "public $value_enum_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " java.util.Map<$boxed_key_type$, $value_enum_type$> map =\n" @@ -569,10 +606,11 @@ GenerateBuilderMembers(io::Printer* printer) const { " }\n" " return map.get(key);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$public Builder put$capitalized_name$(\n" + "$deprecation$public Builder ${$put$capitalized_name$$}$(\n" " $key_type$ key,\n" " $value_enum_type$ value) {\n" " $key_null_check$\n" @@ -581,15 +619,17 @@ GenerateBuilderMembers(io::Printer* printer) const { " instance.getMutable$capitalized_name$Map().put(key, value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$public Builder putAll$capitalized_name$(\n" + "$deprecation$public Builder ${$putAll$capitalized_name$$}$(\n" " java.util.Map<$boxed_key_type$, $value_enum_type$> values) {\n" " copyOnWrite();\n" " instance.getMutable$capitalized_name$Map().putAll(values);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); if (SupportUnknownEnumValue(descriptor_->file())) { printer->Print( variables_, @@ -598,23 +638,25 @@ GenerateBuilderMembers(io::Printer* printer) const { " */\n" "@java.lang.Deprecated\n" "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" - "get$capitalized_name$Value() {\n" + "${$get$capitalized_name$Value$}$() {\n" " return get$capitalized_name$ValueMap();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" "public java.util.Map<$boxed_key_type$, $boxed_value_type$>\n" - "get$capitalized_name$ValueMap() {\n" + "${$get$capitalized_name$ValueMap$}$() {\n" " return java.util.Collections.unmodifiableMap(\n" " instance.get$capitalized_name$ValueMap());\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_type$ get$capitalized_name$ValueOrDefault(\n" + "public $value_type$ ${$get$capitalized_name$ValueOrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue) {\n" " $key_null_check$\n" @@ -622,11 +664,12 @@ GenerateBuilderMembers(io::Printer* printer) const { " instance.get$capitalized_name$ValueMap();\n" " return map.containsKey(key) ? map.get(key) : defaultValue;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_type$ get$capitalized_name$ValueOrThrow(\n" + "public $value_type$ ${$get$capitalized_name$ValueOrThrow$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " java.util.Map<$boxed_key_type$, $boxed_value_type$> map =\n" @@ -636,10 +679,11 @@ GenerateBuilderMembers(io::Printer* printer) const { " }\n" " return map.get(key);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$public Builder put$capitalized_name$Value(\n" + "$deprecation$public Builder ${$put$capitalized_name$Value$}$(\n" " $key_type$ key,\n" " $value_type$ value) {\n" " $key_null_check$\n" @@ -647,15 +691,17 @@ GenerateBuilderMembers(io::Printer* printer) const { " instance.getMutable$capitalized_name$ValueMap().put(key, value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, - "$deprecation$public Builder putAll$capitalized_name$Value(\n" + "$deprecation$public Builder ${$putAll$capitalized_name$Value$}$(\n" " java.util.Map<$boxed_key_type$, $boxed_value_type$> values) {\n" " copyOnWrite();\n" " instance.getMutable$capitalized_name$ValueMap().putAll(values);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } } else { printer->Print( @@ -664,22 +710,26 @@ GenerateBuilderMembers(io::Printer* printer) const { " * Use {@link #get$capitalized_name$Map()} instead.\n" " */\n" "@java.lang.Deprecated\n" - "public java.util.Map<$type_parameters$> get$capitalized_name$() {\n" + "public java.util.Map<$type_parameters$> " + "${$get$capitalized_name$$}$() {\n" " return get$capitalized_name$Map();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$" - "public java.util.Map<$type_parameters$> get$capitalized_name$Map() {\n" + "public java.util.Map<$type_parameters$> " + "${$get$capitalized_name$Map$}$() {\n" " return java.util.Collections.unmodifiableMap(\n" " instance.get$capitalized_name$Map());\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_type$ get$capitalized_name$OrDefault(\n" + "public $value_type$ ${$get$capitalized_name$OrDefault$}$(\n" " $key_type$ key,\n" " $value_type$ defaultValue) {\n" " $key_null_check$\n" @@ -687,11 +737,12 @@ GenerateBuilderMembers(io::Printer* printer) const { " instance.get$capitalized_name$Map();\n" " return map.containsKey(key) ? map.get(key) : defaultValue;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$\n" - "public $value_type$ get$capitalized_name$OrThrow(\n" + "public $value_type$ ${$get$capitalized_name$OrThrow$}$(\n" " $key_type$ key) {\n" " $key_null_check$\n" " java.util.Map<$type_parameters$> map =\n" @@ -701,11 +752,12 @@ GenerateBuilderMembers(io::Printer* printer) const { " }\n" " return map.get(key);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$" - "public Builder put$capitalized_name$(\n" + "public Builder ${$put$capitalized_name$$}$(\n" " $key_type$ key,\n" " $value_type$ value) {\n" " $key_null_check$\n" @@ -714,16 +766,18 @@ GenerateBuilderMembers(io::Printer* printer) const { " instance.getMutable$capitalized_name$Map().put(key, value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print( variables_, "$deprecation$" - "public Builder putAll$capitalized_name$(\n" + "public Builder ${$putAll$capitalized_name$$}$(\n" " java.util.Map<$type_parameters$> values) {\n" " copyOnWrite();\n" " instance.getMutable$capitalized_name$Map().putAll(values);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } } diff --git a/src/google/protobuf/compiler/java/java_message.cc b/src/google/protobuf/compiler/java/java_message.cc index 6e3b4a75..ecc67575 100644 --- a/src/google/protobuf/compiler/java/java_message.cc +++ b/src/google/protobuf/compiler/java/java_message.cc @@ -56,8 +56,9 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/wire_format.h> -#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> +#include <google/protobuf/stubs/strutil.h> + namespace google { namespace protobuf { @@ -253,7 +254,7 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { /* immutable = */ true, "OrBuilder"); if (descriptor_->extension_range_count() > 0) { printer->Print( - "$deprecation$public interface $classname$OrBuilder$idend$ extends\n" + "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n" " $extra_interfaces$\n" " com.google.protobuf.GeneratedMessage$ver$.\n" " ExtendableMessageOrBuilder<$classname$> {\n", @@ -261,19 +262,19 @@ void ImmutableMessageGenerator::GenerateInterface(io::Printer* printer) { "@java.lang.Deprecated " : "", "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "classname", descriptor_->name(), - "idend", "", "ver", GeneratedCodeVersionSuffix()); + "{", "", "}", "", "ver", GeneratedCodeVersionSuffix()); } else { printer->Print( - "$deprecation$public interface $classname$OrBuilder$idend$ extends\n" + "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n" " $extra_interfaces$\n" " com.google.protobuf.MessageOrBuilder {\n", "deprecation", descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "", "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "classname", descriptor_->name(), - "idend", ""); + "{", "", "}", ""); } - printer->Annotate("classname", "idend", descriptor_); + printer->Annotate("{", "}", descriptor_); printer->Indent(); for (int i = 0; i < descriptor_->field_count(); i++) { @@ -345,6 +346,9 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { "com.google.protobuf.GeneratedMessage$0.Builder<?>", GeneratedCodeVersionSuffix()); } + printer->Print( + "private static final long serialVersionUID = 0L;\n"); + printer->Indent(); // Using builder_type, instead of Builder, prevents the Builder class from // being loaded into PermGen space when the default instance is created. @@ -370,15 +374,8 @@ void ImmutableMessageGenerator::Generate(io::Printer* printer) { printer->Print( "@java.lang.Override\n" "public final com.google.protobuf.UnknownFieldSet\n" - "getUnknownFields() {\n"); - if (PreserveUnknownFields(descriptor_)) { - printer->Print( - " return this.unknownFields;\n"); - } else { - printer->Print( - " return com.google.protobuf.UnknownFieldSet.getDefaultInstance();\n"); - } - printer->Print( + "getUnknownFields() {\n" + " return this.unknownFields;\n" "}\n"); if (context_->HasGeneratedMethods(descriptor_)) { @@ -623,14 +620,12 @@ GenerateMessageSerializationMethods(io::Printer* printer) { } } - if (PreserveUnknownFields(descriptor_)) { - if (descriptor_->options().message_set_wire_format()) { - printer->Print( + if (descriptor_->options().message_set_wire_format()) { + printer->Print( "unknownFields.writeAsMessageSetTo(output);\n"); - } else { - printer->Print( + } else { + printer->Print( "unknownFields.writeTo(output);\n"); - } } printer->Outdent(); @@ -658,14 +653,12 @@ GenerateMessageSerializationMethods(io::Printer* printer) { } } - if (PreserveUnknownFields(descriptor_)) { - if (descriptor_->options().message_set_wire_format()) { - printer->Print( + if (descriptor_->options().message_set_wire_format()) { + printer->Print( "size += unknownFields.getSerializedSizeAsMessageSet();\n"); - } else { - printer->Print( + } else { + printer->Print( "size += unknownFields.getSerializedSize();\n"); - } } printer->Outdent(); @@ -674,9 +667,6 @@ GenerateMessageSerializationMethods(io::Printer* printer) { " return size;\n" "}\n" "\n"); - - printer->Print( - "private static final long serialVersionUID = 0L;\n"); } void ImmutableMessageGenerator:: @@ -1078,13 +1068,11 @@ GenerateEqualsAndHashCode(io::Printer* printer) { printer->Print("}\n"); } - if (PreserveUnknownFields(descriptor_)) { - // Always consider unknown fields for equality. This will sometimes return - // false for non-canonical ordering when running in LITE_RUNTIME but it's - // the best we can do. - printer->Print( + // Always consider unknown fields for equality. This will sometimes return + // false for non-canonical ordering when running in LITE_RUNTIME but it's + // the best we can do. + printer->Print( "result = result && unknownFields.equals(other.unknownFields);\n"); - } if (descriptor_->extension_range_count() > 0) { printer->Print( "result = result &&\n" @@ -1226,11 +1214,9 @@ GenerateParsingConstructor(io::Printer* printer) { "bit_field_name", GetBitFieldName(i)); } - if (PreserveUnknownFields(descriptor_)) { - printer->Print( + printer->Print( "com.google.protobuf.UnknownFieldSet.Builder unknownFields =\n" " com.google.protobuf.UnknownFieldSet.newBuilder();\n"); - } printer->Print( "try {\n"); @@ -1247,28 +1233,19 @@ GenerateParsingConstructor(io::Printer* printer) { printer->Indent(); printer->Print( - "case 0:\n" // zero signals EOF / limit reached + "case 0:\n" // zero signals EOF / limit reached " done = true;\n" - " break;\n"); - - if (PreserveUnknownFields(descriptor_)) { - printer->Print( - "default: {\n" - " if (!parseUnknownField(input, unknownFields,\n" - " extensionRegistry, tag)) {\n" - " done = true;\n" // it's an endgroup tag - " }\n" - " break;\n" - "}\n"); - } else { - printer->Print( - "default: {\n" - " if (!input.skipField(tag)) {\n" - " done = true;\n" // it's an endgroup tag - " }\n" - " break;\n" - "}\n"); - } + " break;\n" + "default: {\n" + " if (!parseUnknownField$suffix$(\n" + " input, unknownFields, extensionRegistry, tag)) {\n" + " done = true;\n" // it's an endgroup tag + " }\n" + " break;\n" + "}\n", + "suffix", + descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 ? "Proto3" + : ""); for (int i = 0; i < descriptor_->field_count(); i++) { const FieldDescriptor* field = sorted_fields[i]; @@ -1328,10 +1305,8 @@ GenerateParsingConstructor(io::Printer* printer) { field_generators_.get(field).GenerateParsingDoneCode(printer); } - if (PreserveUnknownFields(descriptor_)) { - // Make unknown fields immutable. - printer->Print("this.unknownFields = unknownFields.build();\n"); - } + // Make unknown fields immutable. + printer->Print("this.unknownFields = unknownFields.build();\n"); // Make extensions immutable. printer->Print( diff --git a/src/google/protobuf/compiler/java/java_message_builder.cc b/src/google/protobuf/compiler/java/java_message_builder.cc index f5643abc..5368c1df 100644 --- a/src/google/protobuf/compiler/java/java_message_builder.cc +++ b/src/google/protobuf/compiler/java/java_message_builder.cc @@ -54,8 +54,9 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/wire_format.h> -#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> +#include <google/protobuf/stubs/strutil.h> + namespace google { namespace protobuf { @@ -171,36 +172,25 @@ Generate(io::Printer* printer) { .GenerateBuilderMembers(printer); } - if (!PreserveUnknownFields(descriptor_)) { - printer->Print( - "public final Builder setUnknownFields(\n" - " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" - " return this;\n" - "}\n" - "\n" - "public final Builder mergeUnknownFields(\n" - " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" - " return this;\n" - "}\n" - "\n"); - } else { + bool is_proto3 = + descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO3; // Override methods declared in GeneratedMessage to return the concrete // generated type so callsites won't depend on GeneratedMessage. This // is needed to keep binary compatibility when we change generated code // to subclass a different GeneratedMessage class (e.g., in v3.0.0 release // we changed all generated code to subclass GeneratedMessageV3). - printer->Print( - "public final Builder setUnknownFields(\n" - " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" - " return super.setUnknownFields(unknownFields);\n" - "}\n" - "\n" - "public final Builder mergeUnknownFields(\n" - " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" - " return super.mergeUnknownFields(unknownFields);\n" - "}\n" - "\n"); - } + printer->Print( + "public final Builder setUnknownFields(\n" + " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" + " return super.setUnknownFields$suffix$(unknownFields);\n" + "}\n" + "\n" + "public final Builder mergeUnknownFields(\n" + " final com.google.protobuf.UnknownFieldSet unknownFields) {\n" + " return super.mergeUnknownFields(unknownFields);\n" + "}\n" + "\n", + "suffix", is_proto3 ? "Proto3" : ""); printer->Print( "\n" @@ -594,10 +584,8 @@ GenerateCommonBuilderMethods(io::Printer* printer) { " this.mergeExtensionFields(other);\n"); } - if (PreserveUnknownFields(descriptor_)) { - printer->Print( - " this.mergeUnknownFields(other.unknownFields);\n"); - } + printer->Print( + " this.mergeUnknownFields(other.unknownFields);\n"); printer->Print( " onChanged();\n"); diff --git a/src/google/protobuf/compiler/java/java_message_field.cc b/src/google/protobuf/compiler/java/java_message_field.cc index ae84db1c..baa7f872 100644 --- a/src/google/protobuf/compiler/java/java_message_field.cc +++ b/src/google/protobuf/compiler/java/java_message_field.cc @@ -150,12 +150,9 @@ GenerateInterfaceMembers(io::Printer* printer) const { // interface so that builders can choose dynamically to either return a // message or a nested builder, so that asking for the interface doesn't // cause a message to ever be built. - if (SupportFieldPresence(descriptor_->file()) || - descriptor_->containing_oneof() == NULL) { - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$boolean has$capitalized_name$();\n"); - } + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, + "$deprecation$boolean has$capitalized_name$();\n"); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n"); @@ -174,39 +171,45 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public $type$OrBuilder " - "get$capitalized_name$OrBuilder() {\n" + "${$get$capitalized_name$OrBuilder$}$() {\n" " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } else { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $name$_ != null;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public $type$OrBuilder " - "get$capitalized_name$OrBuilder() {\n" + "${$get$capitalized_name$OrBuilder$}$() {\n" " return get$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } } @@ -232,6 +235,7 @@ void ImmutableMessageFieldGenerator::PrintNestedBuilderFunction( const char* nested_builder_case, const char* trailing_code) const { printer->Print(variables_, method_prototype); + printer->Annotate("{", "}", descriptor_); printer->Print(" {\n"); printer->Indent(); PrintNestedBuilderCondition(printer, regular_case, nested_builder_case); @@ -267,20 +271,22 @@ GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); if (support_field_presence) { printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_builder$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } else { printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $name$Builder_ != null || $name$_ != null;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } // Field getField() WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public $type$ get$capitalized_name$()", + "$deprecation$public $type$ ${$get$capitalized_name$$}$()", "return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n", "return $name$Builder_.getMessage();\n", NULL); @@ -288,7 +294,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Field.Builder setField(Field value) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder set$capitalized_name$($type$ value)", + "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value)", "if (value == null) {\n" " throw new NullPointerException();\n" @@ -304,7 +310,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Field.Builder setField(Field.Builder builderForValue) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " $type$.Builder builderForValue)", "$name$_ = builderForValue.build();\n" @@ -318,7 +324,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Field.Builder mergeField(Field value) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder merge$capitalized_name$($type$ value)", + "$deprecation$public Builder ${$merge$capitalized_name$$}$($type$ value)", support_field_presence ? "if ($get_has_field_bit_builder$ &&\n" @@ -346,7 +352,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Field.Builder clearField() WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder clear$capitalized_name$()", + "$deprecation$public Builder ${$clear$capitalized_name$$}$()", "$name$_ = null;\n" "$on_changed$\n", @@ -361,14 +367,17 @@ GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$.Builder get$capitalized_name$Builder() {\n" + "$deprecation$public $type$.Builder " + "${$get$capitalized_name$Builder$}$() {\n" " $set_has_field_bit_builder$\n" " $on_changed$\n" " return get$capitalized_name$FieldBuilder().getBuilder();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder() {\n" + "$deprecation$public $type$OrBuilder " + "${$get$capitalized_name$OrBuilder$}$() {\n" " if ($name$Builder_ != null) {\n" " return $name$Builder_.getMessageOrBuilder();\n" " } else {\n" @@ -376,6 +385,7 @@ GenerateBuilderMembers(io::Printer* printer) const { " $type$.getDefaultInstance() : $name$_;\n" " }\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "private com.google.protobuf.SingleFieldBuilder$ver$<\n" @@ -530,30 +540,32 @@ ImmutableMessageOneofFieldGenerator:: void ImmutableMessageOneofFieldGenerator:: GenerateMembers(io::Printer* printer) const { PrintExtraFieldInfo(variables_, printer); - if (SupportFieldPresence(descriptor_->file())) { - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" - " return $has_oneof_case_message$;\n" - "}\n"); - } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" + " return $has_oneof_case_message$;\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " return ($type$) $oneof_name$_;\n" " }\n" " return $type$.getDefaultInstance();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder() {\n" + "$deprecation$public $type$OrBuilder " + "${$get$capitalized_name$OrBuilder$}$() {\n" " if ($has_oneof_case_message$) {\n" " return ($type$) $oneof_name$_;\n" " }\n" " return $type$.getDefaultInstance();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableMessageOneofFieldGenerator:: @@ -571,19 +583,18 @@ GenerateBuilderMembers(io::Printer* printer) const { // The comments above the methods below are based on a hypothetical // field of type "Field" called "Field". - if (SupportFieldPresence(descriptor_->file())) { - // boolean hasField() - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" - " return $has_oneof_case_message$;\n" - "}\n"); - } + // boolean hasField() + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" + " return $has_oneof_case_message$;\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); // Field getField() WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public $type$ get$capitalized_name$()", + "$deprecation$public $type$ ${$get$capitalized_name$$}$()", "if ($has_oneof_case_message$) {\n" " return ($type$) $oneof_name$_;\n" @@ -600,7 +611,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Field.Builder setField(Field value) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder set$capitalized_name$($type$ value)", + "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value)", "if (value == null) {\n" " throw new NullPointerException();\n" @@ -616,7 +627,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Field.Builder setField(Field.Builder builderForValue) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " $type$.Builder builderForValue)", "$oneof_name$_ = builderForValue.build();\n" @@ -630,7 +641,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Field.Builder mergeField(Field value) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder merge$capitalized_name$($type$ value)", + "$deprecation$public Builder ${$merge$capitalized_name$$}$($type$ value)", "if ($has_oneof_case_message$ &&\n" " $oneof_name$_ != $type$.getDefaultInstance()) {\n" @@ -652,7 +663,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Field.Builder clearField() WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder clear$capitalized_name$()", + "$deprecation$public Builder ${$clear$capitalized_name$$}$()", "if ($has_oneof_case_message$) {\n" " $clear_oneof_case_message$;\n" @@ -670,12 +681,15 @@ GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$.Builder get$capitalized_name$Builder() {\n" + "$deprecation$public $type$.Builder " + "${$get$capitalized_name$Builder$}$() {\n" " return get$capitalized_name$FieldBuilder().getBuilder();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder() {\n" + "$deprecation$public $type$OrBuilder " + "${$get$capitalized_name$OrBuilder$}$() {\n" " if (($has_oneof_case_message$) && ($name$Builder_ != null)) {\n" " return $name$Builder_.getMessageOrBuilder();\n" " } else {\n" @@ -685,11 +699,12 @@ GenerateBuilderMembers(io::Printer* printer) const { " return $type$.getDefaultInstance();\n" " }\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "private com.google.protobuf.SingleFieldBuilder$ver$<\n" " $type$, $type$.Builder, $type$OrBuilder> \n" - " get$capitalized_name$FieldBuilder() {\n" + " ${$get$capitalized_name$FieldBuilder$}$() {\n" " if ($name$Builder_ == null) {\n" " if (!($has_oneof_case_message$)) {\n" " $oneof_name$_ = $type$.getDefaultInstance();\n" @@ -705,6 +720,7 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$;\n" " return $name$Builder_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableMessageOneofFieldGenerator:: @@ -833,31 +849,38 @@ GenerateMembers(io::Printer* printer) const { PrintExtraFieldInfo(variables_, printer); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n" + "$deprecation$public java.util.List<$type$> " + "${$get$capitalized_name$List$}$() {\n" " return $name$_;\n" // note: unmodifiable list "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public java.util.List<? extends $type$OrBuilder> \n" - " get$capitalized_name$OrBuilderList() {\n" + " ${$get$capitalized_name$OrBuilderList$}$() {\n" " return $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return $name$_.size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$(int index) {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n" " return $name$_.get(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder(\n" + "$deprecation$public $type$OrBuilder " + "${$get$capitalized_name$OrBuilder$}$(\n" " int index) {\n" " return $name$_.get(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } @@ -883,6 +906,7 @@ void RepeatedImmutableMessageFieldGenerator::PrintNestedBuilderFunction( const char* nested_builder_case, const char* trailing_code) const { printer->Print(variables_, method_prototype); + printer->Annotate("{", "}", descriptor_); printer->Print(" {\n"); printer->Indent(); PrintNestedBuilderCondition(printer, regular_case, nested_builder_case); @@ -934,7 +958,8 @@ GenerateBuilderMembers(io::Printer* printer) const { // List<Field> getRepeatedFieldList() WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public java.util.List<$type$> get$capitalized_name$List()", + "$deprecation$public java.util.List<$type$> " + "${$get$capitalized_name$List$}$()", "return java.util.Collections.unmodifiableList($name$_);\n", "return $name$Builder_.getMessageList();\n", @@ -944,7 +969,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // int getRepeatedFieldCount() WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public int get$capitalized_name$Count()", + "$deprecation$public int ${$get$capitalized_name$Count$}$()", "return $name$_.size();\n", "return $name$Builder_.getCount();\n", @@ -954,7 +979,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Field getRepeatedField(int index) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public $type$ get$capitalized_name$(int index)", + "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index)", "return $name$_.get(index);\n", @@ -965,7 +990,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Builder setRepeatedField(int index, Field value) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value)", "if (value == null) {\n" " throw new NullPointerException();\n" @@ -979,7 +1004,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Builder setRepeatedField(int index, Field.Builder builderForValue) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$.Builder builderForValue)", "ensure$capitalized_name$IsMutable();\n" @@ -993,7 +1018,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Builder addRepeatedField(Field value) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder add$capitalized_name$($type$ value)", + "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value)", "if (value == null) {\n" " throw new NullPointerException();\n" @@ -1010,7 +1035,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Builder addRepeatedField(int index, Field value) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder add$capitalized_name$(\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " int index, $type$ value)", "if (value == null) {\n" @@ -1027,7 +1052,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Builder addRepeatedField(Field.Builder builderForValue) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder add$capitalized_name$(\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " $type$.Builder builderForValue)", "ensure$capitalized_name$IsMutable();\n" @@ -1041,7 +1066,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Builder addRepeatedField(int index, Field.Builder builderForValue) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder add$capitalized_name$(\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " int index, $type$.Builder builderForValue)", "ensure$capitalized_name$IsMutable();\n" @@ -1055,7 +1080,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Builder addAllRepeatedField(Iterable<Field> values) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder addAll$capitalized_name$(\n" + "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<? extends $type$> values)", "ensure$capitalized_name$IsMutable();\n" @@ -1070,7 +1095,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Builder clearAllRepeatedField() WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder clear$capitalized_name$()", + "$deprecation$public Builder ${$clear$capitalized_name$$}$()", "$name$_ = java.util.Collections.emptyList();\n" "$clear_mutable_bit_builder$;\n" @@ -1083,7 +1108,7 @@ GenerateBuilderMembers(io::Printer* printer) const { // Builder removeRepeatedField(int index) WriteFieldDocComment(printer, descriptor_); PrintNestedBuilderFunction(printer, - "$deprecation$public Builder remove$capitalized_name$(int index)", + "$deprecation$public Builder ${$remove$capitalized_name$$}$(int index)", "ensure$capitalized_name$IsMutable();\n" "$name$_.remove(index);\n" @@ -1095,14 +1120,16 @@ GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$.Builder get$capitalized_name$Builder(\n" + "$deprecation$public $type$.Builder ${$get$capitalized_name$Builder$}$(\n" " int index) {\n" " return get$capitalized_name$FieldBuilder().getBuilder(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder(\n" + "$deprecation$public $type$OrBuilder " + "${$get$capitalized_name$OrBuilder$}$(\n" " int index) {\n" " if ($name$Builder_ == null) {\n" " return $name$_.get(index);" @@ -1110,35 +1137,40 @@ GenerateBuilderMembers(io::Printer* printer) const { " return $name$Builder_.getMessageOrBuilder(index);\n" " }\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public java.util.List<? extends $type$OrBuilder> \n" - " get$capitalized_name$OrBuilderList() {\n" + " ${$get$capitalized_name$OrBuilderList$}$() {\n" " if ($name$Builder_ != null) {\n" " return $name$Builder_.getMessageOrBuilderList();\n" " } else {\n" " return java.util.Collections.unmodifiableList($name$_);\n" " }\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$.Builder add$capitalized_name$Builder() {\n" + "$deprecation$public $type$.Builder " + "${$add$capitalized_name$Builder$}$() {\n" " return get$capitalized_name$FieldBuilder().addBuilder(\n" " $type$.getDefaultInstance());\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$.Builder add$capitalized_name$Builder(\n" + "$deprecation$public $type$.Builder ${$add$capitalized_name$Builder$}$(\n" " int index) {\n" " return get$capitalized_name$FieldBuilder().addBuilder(\n" " index, $type$.getDefaultInstance());\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public java.util.List<$type$.Builder> \n" - " get$capitalized_name$BuilderList() {\n" + " ${$get$capitalized_name$BuilderList$}$() {\n" " return get$capitalized_name$FieldBuilder().getBuilderList();\n" "}\n" "private com.google.protobuf.RepeatedFieldBuilder$ver$<\n" @@ -1155,6 +1187,7 @@ GenerateBuilderMembers(io::Printer* printer) const { " }\n" " return $name$Builder_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void RepeatedImmutableMessageFieldGenerator:: diff --git a/src/google/protobuf/compiler/java/java_message_field_lite.cc b/src/google/protobuf/compiler/java/java_message_field_lite.cc index c71e9101..df3e80d4 100644 --- a/src/google/protobuf/compiler/java/java_message_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_field_lite.cc @@ -129,16 +129,9 @@ int ImmutableMessageFieldLiteGenerator::GetNumBitsForBuilder() const { void ImmutableMessageFieldLiteGenerator:: GenerateInterfaceMembers(io::Printer* printer) const { - // TODO(jonp): In the future, consider having a method specific to the - // interface so that builders can choose dynamically to either return a - // message or a nested builder, so that asking for the interface doesn't - // cause a message to ever be built. - if (SupportFieldPresence(descriptor_->file()) || - descriptor_->containing_oneof() == NULL) { - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$boolean has$capitalized_name$();\n"); - } + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, + "$deprecation$boolean has$capitalized_name$();\n"); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n"); @@ -154,25 +147,29 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } else { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $name$_ != null;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } // Field.Builder setField(Field value) @@ -226,53 +223,60 @@ GenerateBuilderMembers(io::Printer* printer) const { // boolean hasField() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return instance.has$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Field getField() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Field.Builder setField(Field value) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(value);\n" " return this;\n" " }\n"); + printer->Annotate("{", "}", descriptor_); // Field.Builder setField(Field.Builder builderForValue) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " $type$.Builder builderForValue) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(builderForValue);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Field.Builder mergeField(Field value) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder merge$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder " + "${$merge$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" " instance.merge$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Field.Builder clearField() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableMessageFieldLiteGenerator:: @@ -390,21 +394,21 @@ ImmutableMessageOneofFieldLiteGenerator:: void ImmutableMessageOneofFieldLiteGenerator:: GenerateMembers(io::Printer* printer) const { PrintExtraFieldInfo(variables_, printer); - if (SupportFieldPresence(descriptor_->file())) { - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" - " return $has_oneof_case_message$;\n" - "}\n"); - } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" + " return $has_oneof_case_message$;\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " return ($type$) $oneof_name$_;\n" " }\n" " return $type$.getDefaultInstance();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Field.Builder setField(Field value) WriteFieldDocComment(printer, descriptor_); @@ -457,58 +461,63 @@ GenerateBuilderMembers(io::Printer* printer) const { // The comments above the methods below are based on a hypothetical // field of type "Field" called "Field". - if (SupportFieldPresence(descriptor_->file())) { - // boolean hasField() - WriteFieldDocComment(printer, descriptor_); - printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" - " return instance.has$capitalized_name$();\n" - "}\n"); - } + // boolean hasField() + WriteFieldDocComment(printer, descriptor_); + printer->Print(variables_, + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" + " return instance.has$capitalized_name$();\n" + "}\n"); + printer->Annotate("{", "}", descriptor_); // Field getField() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Field.Builder setField(Field value) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Field.Builder setField(Field.Builder builderForValue) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " $type$.Builder builderForValue) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(builderForValue);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Field.Builder mergeField(Field value) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder merge$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder " + "${$merge$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" " instance.merge$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Field.Builder clearField() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableMessageOneofFieldLiteGenerator:: @@ -615,31 +624,38 @@ GenerateMembers(io::Printer* printer) const { PrintExtraFieldInfo(variables_, printer); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n" + "$deprecation$public java.util.List<$type$> " + "${$get$capitalized_name$List$}$() {\n" " return $name$_;\n" // note: unmodifiable list "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public java.util.List<? extends $type$OrBuilder> \n" - " get$capitalized_name$OrBuilderList() {\n" + " ${$get$capitalized_name$OrBuilderList$}$() {\n" " return $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return $name$_.size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$(int index) {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n" " return $name$_.get(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$OrBuilder get$capitalized_name$OrBuilder(\n" + "$deprecation$public $type$OrBuilder " + "${$get$capitalized_name$OrBuilder$}$(\n" " int index) {\n" " return $name$_.get(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); printer->Print(variables_, "private void ensure$capitalized_name$IsMutable() {\n" @@ -745,110 +761,123 @@ GenerateBuilderMembers(io::Printer* printer) const { // List<Field> getRepeatedFieldList() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.util.List<$type$> get$capitalized_name$List() {\n" + "$deprecation$public java.util.List<$type$> " + "${$get$capitalized_name$List$}$() {\n" " return java.util.Collections.unmodifiableList(\n" " instance.get$capitalized_name$List());\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // int getRepeatedFieldCount() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return instance.get$capitalized_name$Count();\n" "}"); + printer->Annotate("{", "}", descriptor_); // Field getRepeatedField(int index) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$(int index) {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n" " return instance.get$capitalized_name$(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Builder setRepeatedField(int index, Field value) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(index, value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Builder setRepeatedField(int index, Field.Builder builderForValue) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$.Builder builderForValue) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(index, builderForValue);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Builder addRepeatedField(Field value) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" " instance.add$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Builder addRepeatedField(int index, Field value) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$(\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " int index, $type$ value) {\n" " copyOnWrite();\n" " instance.add$capitalized_name$(index, value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Builder addRepeatedField(Field.Builder builderForValue) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$(\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " $type$.Builder builderForValue) {\n" " copyOnWrite();\n" " instance.add$capitalized_name$(builderForValue);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Builder addRepeatedField(int index, Field.Builder builderForValue) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$(\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " int index, $type$.Builder builderForValue) {\n" " copyOnWrite();\n" " instance.add$capitalized_name$(index, builderForValue);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Builder addAllRepeatedField(Iterable<Field> values) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder addAll$capitalized_name$(\n" + "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<? extends $type$> values) {\n" " copyOnWrite();\n" " instance.addAll$capitalized_name$(values);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Builder clearAllRepeatedField() WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); // Builder removeRepeatedField(int index) WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder remove$capitalized_name$(int index) {\n" + "$deprecation$public Builder ${$remove$capitalized_name$$}$(int index) {\n" " copyOnWrite();\n" " instance.remove$capitalized_name$(index);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void RepeatedImmutableMessageFieldLiteGenerator:: diff --git a/src/google/protobuf/compiler/java/java_message_lite.cc b/src/google/protobuf/compiler/java/java_message_lite.cc index 5007ecee..26f16439 100644 --- a/src/google/protobuf/compiler/java/java_message_lite.cc +++ b/src/google/protobuf/compiler/java/java_message_lite.cc @@ -56,8 +56,9 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/wire_format.h> -#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> +#include <google/protobuf/stubs/strutil.h> + namespace google { namespace protobuf { @@ -124,7 +125,7 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { /* immutable = */ true, "OrBuilder"); if (descriptor_->extension_range_count() > 0) { printer->Print( - "$deprecation$public interface $classname$OrBuilder$idend$ extends \n" + "$deprecation$public interface ${$$classname$OrBuilder$}$ extends \n" " $extra_interfaces$\n" " com.google.protobuf.GeneratedMessageLite.\n" " ExtendableMessageOrBuilder<\n" @@ -133,19 +134,19 @@ void ImmutableMessageLiteGenerator::GenerateInterface(io::Printer* printer) { "@java.lang.Deprecated " : "", "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "classname", descriptor_->name(), - "idend", ""); + "{", "", "}", ""); } else { printer->Print( - "$deprecation$public interface $classname$OrBuilder$idend$ extends\n" + "$deprecation$public interface ${$$classname$OrBuilder$}$ extends\n" " $extra_interfaces$\n" " com.google.protobuf.MessageLiteOrBuilder {\n", "deprecation", descriptor_->options().deprecated() ? "@java.lang.Deprecated " : "", "extra_interfaces", ExtraMessageOrBuilderInterfaces(descriptor_), "classname", descriptor_->name(), - "idend", ""); + "{", "", "}", ""); } - printer->Annotate("classname", "idend", descriptor_); + printer->Annotate("{", "}", descriptor_); printer->Indent(); for (int i = 0; i < descriptor_->field_count(); i++) { @@ -345,15 +346,15 @@ void ImmutableMessageLiteGenerator::Generate(io::Printer* printer) { } printer->Print( - "@java.lang.SuppressWarnings({\"unchecked\", \"fallthrough\"})\n" - "protected final Object dynamicMethod(\n" - " com.google.protobuf.GeneratedMessageLite.MethodToInvoke method,\n" - " Object arg0, Object arg1) {\n" - " switch (method) {\n" - " case NEW_MUTABLE_INSTANCE: {\n" - " return new $classname$();\n" - " }\n", - "classname", name_resolver_->GetImmutableClassName(descriptor_)); + "@java.lang.SuppressWarnings({\"unchecked\", \"fallthrough\"})\n" + "protected final java.lang.Object dynamicMethod(\n" + " com.google.protobuf.GeneratedMessageLite.MethodToInvoke method,\n" + " java.lang.Object arg0, java.lang.Object arg1) {\n" + " switch (method) {\n" + " case NEW_MUTABLE_INSTANCE: {\n" + " return new $classname$();\n" + " }\n", + "classname", name_resolver_->GetImmutableClassName(descriptor_)); printer->Indent(); printer->Indent(); @@ -530,14 +531,12 @@ GenerateMessageSerializationMethods(io::Printer* printer) { } } - if (PreserveUnknownFields(descriptor_)) { - if (descriptor_->options().message_set_wire_format()) { - printer->Print( - "unknownFields.writeAsMessageSetTo(output);\n"); - } else { - printer->Print( - "unknownFields.writeTo(output);\n"); - } + if (descriptor_->options().message_set_wire_format()) { + printer->Print( + "unknownFields.writeAsMessageSetTo(output);\n"); + } else { + printer->Print( + "unknownFields.writeTo(output);\n"); } printer->Outdent(); @@ -565,14 +564,12 @@ GenerateMessageSerializationMethods(io::Printer* printer) { } } - if (PreserveUnknownFields(descriptor_)) { - if (descriptor_->options().message_set_wire_format()) { - printer->Print( - "size += unknownFields.getSerializedSizeAsMessageSet();\n"); - } else { - printer->Print( - "size += unknownFields.getSerializedSize();\n"); - } + if (descriptor_->options().message_set_wire_format()) { + printer->Print( + "size += unknownFields.getSerializedSizeAsMessageSet();\n"); + } else { + printer->Print( + "size += unknownFields.getSerializedSize();\n"); } printer->Outdent(); @@ -968,41 +965,31 @@ void ImmutableMessageLiteGenerator::GenerateDynamicMethodMergeFromStream( " done = true;\n" " break;\n"); - if (PreserveUnknownFields(descriptor_)) { - if (descriptor_->extension_range_count() > 0) { - if (descriptor_->options().message_set_wire_format()) { - printer->Print( - "default: {\n" - " if (!parseUnknownFieldAsMessageSet(\n" - " getDefaultInstanceForType(), input, extensionRegistry,\n" - " tag)) {\n" - " done = true;\n" // it's an endgroup tag - " }\n" - " break;\n" - "}\n"); - } else { - printer->Print( - "default: {\n" - " if (!parseUnknownField(getDefaultInstanceForType(),\n" - " input, extensionRegistry, tag)) {\n" - " done = true;\n" // it's an endgroup tag - " }\n" - " break;\n" - "}\n"); - } + if (descriptor_->extension_range_count() > 0) { + if (descriptor_->options().message_set_wire_format()) { + printer->Print( + "default: {\n" + " if (!parseUnknownFieldAsMessageSet(\n" + " getDefaultInstanceForType(), input, extensionRegistry,\n" + " tag)) {\n" + " done = true;\n" // it's an endgroup tag + " }\n" + " break;\n" + "}\n"); } else { printer->Print( - "default: {\n" - " if (!parseUnknownField(tag, input)) {\n" - " done = true;\n" // it's an endgroup tag - " }\n" - " break;\n" - "}\n"); + "default: {\n" + " if (!parseUnknownField(getDefaultInstanceForType(),\n" + " input, extensionRegistry, tag)) {\n" + " done = true;\n" // it's an endgroup tag + " }\n" + " break;\n" + "}\n"); } } else { printer->Print( "default: {\n" - " if (!input.skipField(tag)) {\n" + " if (!parseUnknownField(tag, input)) {\n" " done = true;\n" // it's an endgroup tag " }\n" " break;\n" diff --git a/src/google/protobuf/compiler/java/java_name_resolver.cc b/src/google/protobuf/compiler/java/java_name_resolver.cc index bffe4f16..1673b4ee 100644 --- a/src/google/protobuf/compiler/java/java_name_resolver.cc +++ b/src/google/protobuf/compiler/java/java_name_resolver.cc @@ -33,6 +33,7 @@ #include <map> #include <string> + #include <google/protobuf/compiler/java/java_helpers.h> #include <google/protobuf/stubs/substitute.h> diff --git a/src/google/protobuf/compiler/java/java_primitive_field.cc b/src/google/protobuf/compiler/java/java_primitive_field.cc index 840252e7..074a6be8 100644 --- a/src/google/protobuf/compiler/java/java_primitive_field.cc +++ b/src/google/protobuf/compiler/java/java_primitive_field.cc @@ -190,16 +190,18 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutablePrimitiveFieldGenerator:: @@ -210,31 +212,35 @@ GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_builder$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n" "$null_check$" " $set_has_field_bit_builder$\n" " $name$_ = value;\n" " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " $clear_has_field_bit_builder$\n"); + printer->Annotate("{", "}", descriptor_); JavaType type = GetJavaType(descriptor_); if (type == JAVATYPE_STRING || type == JAVATYPE_BYTES) { // The default value is not a simple literal so we want to avoid executing @@ -441,19 +447,21 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " return ($boxed_type$) $oneof_name$_;\n" " }\n" " return $default$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } @@ -462,33 +470,36 @@ GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " return ($boxed_type$) $oneof_name$_;\n" " }\n" " return $default$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n" "$null_check$" " $set_oneof_case_message$;\n" " $oneof_name$_ = value;\n" " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " $clear_oneof_case_message$;\n" " $oneof_name$_ = null;\n" @@ -496,6 +507,7 @@ GenerateBuilderMembers(io::Printer* printer) const { " }\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutablePrimitiveOneofFieldGenerator:: @@ -604,19 +616,22 @@ GenerateMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public java.util.List<$boxed_type$>\n" - " get$capitalized_name$List() {\n" + " ${$get$capitalized_name$List$}$() {\n" " return $name$_;\n" // note: unmodifiable list "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return $name$_.size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$(int index) {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n" " return $name$_.get(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); if (descriptor_->is_packed() && context_->HasGeneratedMethods(descriptor_->containing_type())) { @@ -654,22 +669,25 @@ GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public java.util.List<$boxed_type$>\n" - " get$capitalized_name$List() {\n" + " ${$get$capitalized_name$List$}$() {\n" " return java.util.Collections.unmodifiableList($name$_);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return $name$_.size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$(int index) {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n" " return $name$_.get(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value) {\n" "$null_check$" " ensure$capitalized_name$IsMutable();\n" @@ -677,18 +695,20 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value) {\n" "$null_check$" " ensure$capitalized_name$IsMutable();\n" " $name$_.add(value);\n" " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder addAll$capitalized_name$(\n" + "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<? extends $boxed_type$> values) {\n" " ensure$capitalized_name$IsMutable();\n" " com.google.protobuf.AbstractMessageLite.Builder.addAll(\n" @@ -696,14 +716,16 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " $name$_ = $empty_list$;\n" " $clear_mutable_bit_builder$;\n" " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void RepeatedImmutablePrimitiveFieldGenerator:: diff --git a/src/google/protobuf/compiler/java/java_primitive_field_lite.cc b/src/google/protobuf/compiler/java/java_primitive_field_lite.cc index 0e8e492f..f9293171 100644 --- a/src/google/protobuf/compiler/java/java_primitive_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_primitive_field_lite.cc @@ -222,16 +222,18 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, @@ -264,32 +266,36 @@ GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return instance.has$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutablePrimitiveFieldLiteGenerator:: @@ -482,19 +488,21 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " return ($boxed_type$) $oneof_name$_;\n" " }\n" " return $default$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, @@ -520,32 +528,36 @@ GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return instance.has$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$() {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutablePrimitiveOneofFieldLiteGenerator:: @@ -634,21 +646,24 @@ GenerateMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public java.util.List<$boxed_type$>\n" - " get$capitalized_name$List() {\n" + " ${$get$capitalized_name$List$}$() {\n" " return $name$_;\n" // note: unmodifiable list "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return $name$_.size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$(int index) {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n" " return $repeated_get$(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); - if (descriptor_->options().packed() && + if (descriptor_->is_packed() && context_->HasGeneratedMethods(descriptor_->containing_type())) { printer->Print(variables_, "private int $name$MemoizedSerializedSize = -1;\n"); @@ -697,50 +712,57 @@ GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public java.util.List<$boxed_type$>\n" - " get$capitalized_name$List() {\n" + " ${$get$capitalized_name$List$}$() {\n" " return java.util.Collections.unmodifiableList(\n" " instance.get$capitalized_name$List());\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return instance.get$capitalized_name$Count();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public $type$ get$capitalized_name$(int index) {\n" + "$deprecation$public $type$ ${$get$capitalized_name$$}$(int index) {\n" " return instance.get$capitalized_name$(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, $type$ value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(index, value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$($type$ value) {\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$($type$ value) {\n" " copyOnWrite();\n" " instance.add$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder addAll$capitalized_name$(\n" + "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<? extends $boxed_type$> values) {\n" " copyOnWrite();\n" " instance.addAll$capitalized_name$(values);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void RepeatedImmutablePrimitiveFieldLiteGenerator:: @@ -829,7 +851,7 @@ GenerateParsingDoneCode(io::Printer* printer) const { void RepeatedImmutablePrimitiveFieldLiteGenerator:: GenerateSerializationCode(io::Printer* printer) const { - if (descriptor_->options().packed()) { + if (descriptor_->is_packed()) { // We invoke getSerializedSize in writeTo for messages that have packed // fields in ImmutableMessageGenerator::GenerateMessageSerializationMethods. // That makes it safe to rely on the memoized size here. @@ -870,7 +892,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const { printer->Print( "size += dataSize;\n"); - if (descriptor_->options().packed()) { + if (descriptor_->is_packed()) { printer->Print(variables_, "if (!get$capitalized_name$List().isEmpty()) {\n" " size += $tag_size$;\n" @@ -883,7 +905,7 @@ GenerateSerializedSizeCode(io::Printer* printer) const { } // cache the data size for packed fields. - if (descriptor_->options().packed()) { + if (descriptor_->is_packed()) { printer->Print(variables_, "$name$MemoizedSerializedSize = dataSize;\n"); } diff --git a/src/google/protobuf/compiler/java/java_string_field.cc b/src/google/protobuf/compiler/java/java_string_field.cc index 5c2900ce..2b6e9381 100644 --- a/src/google/protobuf/compiler/java/java_string_field.cc +++ b/src/google/protobuf/compiler/java/java_string_field.cc @@ -217,14 +217,15 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.lang.String get$capitalized_name$() {\n" + "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n" " java.lang.Object ref = $name$_;\n" " if (ref instanceof java.lang.String) {\n" " return (java.lang.String) ref;\n" @@ -232,6 +233,7 @@ GenerateMembers(io::Printer* printer) const { " com.google.protobuf.ByteString bs = \n" " (com.google.protobuf.ByteString) ref;\n" " java.lang.String s = bs.toStringUtf8();\n"); + printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " $name$_ = s;\n"); @@ -248,7 +250,7 @@ GenerateMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" - " get$capitalized_name$Bytes() {\n" + " ${$get$capitalized_name$Bytes$}$() {\n" " java.lang.Object ref = $name$_;\n" " if (ref instanceof java.lang.String) {\n" " com.google.protobuf.ByteString b = \n" @@ -260,6 +262,7 @@ GenerateMembers(io::Printer* printer) const { " return (com.google.protobuf.ByteString) ref;\n" " }\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableStringFieldGenerator:: @@ -269,19 +272,21 @@ GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_builder$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.lang.String get$capitalized_name$() {\n" + "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n" " java.lang.Object ref = $name$_;\n" " if (!(ref instanceof java.lang.String)) {\n" " com.google.protobuf.ByteString bs =\n" " (com.google.protobuf.ByteString) ref;\n" " java.lang.String s = bs.toStringUtf8();\n"); + printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " $name$_ = s;\n"); @@ -301,7 +306,7 @@ GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" - " get$capitalized_name$Bytes() {\n" + " ${$get$capitalized_name$Bytes$}$() {\n" " java.lang.Object ref = $name$_;\n" " if (ref instanceof String) {\n" " com.google.protobuf.ByteString b = \n" @@ -313,10 +318,11 @@ GenerateBuilderMembers(io::Printer* printer) const { " return (com.google.protobuf.ByteString) ref;\n" " }\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" "$null_check$" " $set_has_field_bit_builder$\n" @@ -324,10 +330,12 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " $clear_has_field_bit_builder$\n"); + printer->Annotate("{", "}", descriptor_); // The default value is not a simple literal so we want to avoid executing // it multiple times. Instead, get the default out of the default instance. printer->Print(variables_, @@ -339,9 +347,10 @@ GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$Bytes(\n" + "$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" "$null_check$"); + printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); @@ -482,14 +491,15 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.lang.String get$capitalized_name$() {\n" + "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n" " java.lang.Object ref $default_init$;\n" " if ($has_oneof_case_message$) {\n" " ref = $oneof_name$_;\n" @@ -500,6 +510,7 @@ GenerateMembers(io::Printer* printer) const { " com.google.protobuf.ByteString bs = \n" " (com.google.protobuf.ByteString) ref;\n" " java.lang.String s = bs.toStringUtf8();\n"); + printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " if ($has_oneof_case_message$) {\n" @@ -519,7 +530,7 @@ GenerateMembers(io::Printer* printer) const { printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" - " get$capitalized_name$Bytes() {\n" + " ${$get$capitalized_name$Bytes$}$() {\n" " java.lang.Object ref $default_init$;\n" " if ($has_oneof_case_message$) {\n" " ref = $oneof_name$_;\n" @@ -536,6 +547,7 @@ GenerateMembers(io::Printer* printer) const { " return (com.google.protobuf.ByteString) ref;\n" " }\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableStringOneofFieldGenerator:: @@ -543,14 +555,15 @@ GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.lang.String get$capitalized_name$() {\n" + "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n" " java.lang.Object ref $default_init$;\n" " if ($has_oneof_case_message$) {\n" " ref = $oneof_name$_;\n" @@ -560,6 +573,7 @@ GenerateBuilderMembers(io::Printer* printer) const { " (com.google.protobuf.ByteString) ref;\n" " java.lang.String s = bs.toStringUtf8();\n" " if ($has_oneof_case_message$) {\n"); + printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " $oneof_name$_ = s;\n"); @@ -580,7 +594,7 @@ GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" - " get$capitalized_name$Bytes() {\n" + " ${$get$capitalized_name$Bytes$}$() {\n" " java.lang.Object ref $default_init$;\n" " if ($has_oneof_case_message$) {\n" " ref = $oneof_name$_;\n" @@ -597,10 +611,11 @@ GenerateBuilderMembers(io::Printer* printer) const { " return (com.google.protobuf.ByteString) ref;\n" " }\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" "$null_check$" " $set_oneof_case_message$;\n" @@ -608,9 +623,10 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " $clear_oneof_case_message$;\n" " $oneof_name$_ = null;\n" @@ -618,12 +634,14 @@ GenerateBuilderMembers(io::Printer* printer) const { " }\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$Bytes(\n" + "$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" "$null_check$"); + printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); @@ -744,25 +762,30 @@ GenerateMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ProtocolStringList\n" - " get$capitalized_name$List() {\n" + " ${$get$capitalized_name$List$}$() {\n" " return $name$_;\n" // note: unmodifiable list "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return $name$_.size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.lang.String get$capitalized_name$(int index) {\n" + "$deprecation$public java.lang.String " + "${$get$capitalized_name$$}$(int index) {\n" " return $name$_.get(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" - " get$capitalized_name$Bytes(int index) {\n" + " ${$get$capitalized_name$Bytes$}$(int index) {\n" " return $name$_.getByteString(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void RepeatedImmutableStringFieldGenerator:: @@ -794,28 +817,33 @@ GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ProtocolStringList\n" - " get$capitalized_name$List() {\n" + " ${$get$capitalized_name$List$}$() {\n" " return $name$_.getUnmodifiableView();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return $name$_.size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.lang.String get$capitalized_name$(int index) {\n" + "$deprecation$public java.lang.String " + "${$get$capitalized_name$$}$(int index) {\n" " return $name$_.get(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" - " get$capitalized_name$Bytes(int index) {\n" + " ${$get$capitalized_name$Bytes$}$(int index) {\n" " return $name$_.getByteString(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, java.lang.String value) {\n" "$null_check$" " ensure$capitalized_name$IsMutable();\n" @@ -823,9 +851,10 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$(\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " java.lang.String value) {\n" "$null_check$" " ensure$capitalized_name$IsMutable();\n" @@ -833,9 +862,10 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder addAll$capitalized_name$(\n" + "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<java.lang.String> values) {\n" " ensure$capitalized_name$IsMutable();\n" " com.google.protobuf.AbstractMessageLite.Builder.addAll(\n" @@ -843,20 +873,23 @@ GenerateBuilderMembers(io::Printer* printer) const { " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " $name$_ = $empty_list$;\n" " $clear_mutable_bit_builder$;\n" " $on_changed$\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$Bytes(\n" + "$deprecation$public Builder ${$add$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" "$null_check$"); + printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); diff --git a/src/google/protobuf/compiler/java/java_string_field_lite.cc b/src/google/protobuf/compiler/java/java_string_field_lite.cc index 7e3ad1d0..adda307c 100644 --- a/src/google/protobuf/compiler/java/java_string_field_lite.cc +++ b/src/google/protobuf/compiler/java/java_string_field_lite.cc @@ -71,7 +71,7 @@ void SetPrimitiveVariables(const FieldDescriptor* descriptor, (*variables)["default"] = ImmutableDefaultValue(descriptor, name_resolver); (*variables)["default_init"] = "= " + ImmutableDefaultValue(descriptor, name_resolver); - (*variables)["capitalized_type"] = "String"; + (*variables)["capitalized_type"] = "java.lang.String"; (*variables)["tag"] = SimpleItoa(static_cast<int32>(WireFormat::MakeTag(descriptor))); (*variables)["tag_size"] = SimpleItoa( @@ -192,22 +192,25 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $get_has_field_bit_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.lang.String get$capitalized_name$() {\n" + "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n" " return $name$_;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" - " get$capitalized_name$Bytes() {\n" + " ${$get$capitalized_name$Bytes$}$() {\n" " return com.google.protobuf.ByteString.copyFromUtf8($name$_);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, @@ -246,48 +249,54 @@ GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return instance.has$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.lang.String get$capitalized_name$() {\n" + "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" - " get$capitalized_name$Bytes() {\n" + " ${$get$capitalized_name$Bytes$}$() {\n" " return instance.get$capitalized_name$Bytes();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$Bytes(\n" + "$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$Bytes(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableStringFieldLiteGenerator:: @@ -324,7 +333,7 @@ void ImmutableStringFieldLiteGenerator:: GenerateParsingCode(io::Printer* printer) const { if (CheckUtf8(descriptor_)) { printer->Print(variables_, - "String s = input.readStringRequireUtf8();\n" + "java.lang.String s = input.readStringRequireUtf8();\n" "$set_has_field_bit_message$\n" "$name$_ = s;\n"); } else { @@ -333,7 +342,7 @@ GenerateParsingCode(io::Printer* printer) const { // spurious intermediary ByteString allocations, cutting overall allocations // in half. printer->Print(variables_, - "String s = input.readString();\n" + "java.lang.String s = input.readString();\n" "$set_has_field_bit_message$\n" "$name$_ = s;\n"); } @@ -410,54 +419,60 @@ GenerateMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return $has_oneof_case_message$;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.lang.String get$capitalized_name$() {\n" + "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n" " java.lang.String ref $default_init$;\n" " if ($has_oneof_case_message$) {\n" " ref = (java.lang.String) $oneof_name$_;\n" " }\n" " return ref;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" - " get$capitalized_name$Bytes() {\n" + " ${$get$capitalized_name$Bytes$}$() {\n" " java.lang.String ref $default_init$;\n" " if ($has_oneof_case_message$) {\n" " ref = (java.lang.String) $oneof_name$_;\n" " }\n" " return com.google.protobuf.ByteString.copyFromUtf8(ref);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "private void set$capitalized_name$(\n" + "private void ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" "$null_check$" " $set_oneof_case_message$;\n" " $oneof_name$_ = value;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "private void clear$capitalized_name$() {\n" + "private void ${$clear$capitalized_name$$}$() {\n" " if ($has_oneof_case_message$) {\n" " $clear_oneof_case_message$;\n" " $oneof_name$_ = null;\n" " }\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "private void set$capitalized_name$Bytes(\n" + "private void ${$set$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" "$null_check$"); + printer->Annotate("{", "}", descriptor_); if (CheckUtf8(descriptor_)) { printer->Print(variables_, " checkByteStringIsUtf8(value);\n"); @@ -474,48 +489,54 @@ GenerateBuilderMembers(io::Printer* printer) const { if (SupportFieldPresence(descriptor_->file())) { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public boolean has$capitalized_name$() {\n" + "$deprecation$public boolean ${$has$capitalized_name$$}$() {\n" " return instance.has$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.lang.String get$capitalized_name$() {\n" + "$deprecation$public java.lang.String ${$get$capitalized_name$$}$() {\n" " return instance.get$capitalized_name$();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" - " get$capitalized_name$Bytes() {\n" + " ${$get$capitalized_name$Bytes$}$() {\n" " return instance.get$capitalized_name$Bytes();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " java.lang.String value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$Bytes(\n" + "$deprecation$public Builder ${$set$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$Bytes(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void ImmutableStringOneofFieldLiteGenerator:: @@ -529,7 +550,7 @@ void ImmutableStringOneofFieldLiteGenerator:: GenerateParsingCode(io::Printer* printer) const { if (CheckUtf8(descriptor_)) { printer->Print(variables_, - "String s = input.readStringRequireUtf8();\n" + "java.lang.String s = input.readStringRequireUtf8();\n" "$set_oneof_case_message$;\n" "$oneof_name$_ = s;\n"); } else { @@ -538,7 +559,7 @@ GenerateParsingCode(io::Printer* printer) const { // spurious intermediary ByteString allocations, cutting overall allocations // in half. printer->Print(variables_, - "String s = input.readString();\n" + "java.lang.String s = input.readString();\n" "$set_oneof_case_message$;\n" "$oneof_name$_ = s;\n"); } @@ -597,7 +618,7 @@ void RepeatedImmutableStringFieldLiteGenerator:: GenerateInterfaceMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$java.util.List<String>\n" + "$deprecation$java.util.List<java.lang.String>\n" " get$capitalized_name$List();\n"); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, @@ -615,30 +636,37 @@ GenerateInterfaceMembers(io::Printer* printer) const { void RepeatedImmutableStringFieldLiteGenerator:: GenerateMembers(io::Printer* printer) const { printer->Print(variables_, - "private com.google.protobuf.Internal.ProtobufList<String> $name$_;\n"); + "private com.google.protobuf.Internal.ProtobufList<java.lang.String> " + "$name$_;\n"); PrintExtraFieldInfo(variables_, printer); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.util.List<String> get$capitalized_name$List() {\n" - " return $name$_;\n" // note: unmodifiable list + "$deprecation$public java.util.List<java.lang.String> " + "${$get$capitalized_name$List$}$() {\n" + " return $name$_;\n" // note: unmodifiable list "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return $name$_.size();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.lang.String get$capitalized_name$(int index) {\n" + "$deprecation$public java.lang.String " + "${$get$capitalized_name$$}$(int index) {\n" " return $name$_.get(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" - " get$capitalized_name$Bytes(int index) {\n" + " ${$get$capitalized_name$Bytes$}$(int index) {\n" " return com.google.protobuf.ByteString.copyFromUtf8(\n" " $name$_.get(index));\n" "}\n"); + printer->Annotate("{", "}", descriptor_); printer->Print(variables_, "private void ensure$capitalized_name$IsMutable() {\n" @@ -697,67 +725,77 @@ void RepeatedImmutableStringFieldLiteGenerator:: GenerateBuilderMembers(io::Printer* printer) const { WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.util.List<String>\n" - " get$capitalized_name$List() {\n" + "$deprecation$public java.util.List<java.lang.String>\n" + " ${$get$capitalized_name$List$}$() {\n" " return java.util.Collections.unmodifiableList(\n" " instance.get$capitalized_name$List());\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public int get$capitalized_name$Count() {\n" + "$deprecation$public int ${$get$capitalized_name$Count$}$() {\n" " return instance.get$capitalized_name$Count();\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public java.lang.String get$capitalized_name$(int index) {\n" + "$deprecation$public java.lang.String " + "${$get$capitalized_name$$}$(int index) {\n" " return instance.get$capitalized_name$(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, "$deprecation$public com.google.protobuf.ByteString\n" - " get$capitalized_name$Bytes(int index) {\n" + " ${$get$capitalized_name$Bytes$}$(int index) {\n" " return instance.get$capitalized_name$Bytes(index);\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder set$capitalized_name$(\n" + "$deprecation$public Builder ${$set$capitalized_name$$}$(\n" " int index, java.lang.String value) {\n" " copyOnWrite();\n" " instance.set$capitalized_name$(index, value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$(\n" + "$deprecation$public Builder ${$add$capitalized_name$$}$(\n" " java.lang.String value) {\n" " copyOnWrite();\n" " instance.add$capitalized_name$(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder addAll$capitalized_name$(\n" + "$deprecation$public Builder ${$addAll$capitalized_name$$}$(\n" " java.lang.Iterable<java.lang.String> values) {\n" " copyOnWrite();\n" " instance.addAll$capitalized_name$(values);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder clear$capitalized_name$() {\n" + "$deprecation$public Builder ${$clear$capitalized_name$$}$() {\n" " copyOnWrite();\n" " instance.clear$capitalized_name$();\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); WriteFieldDocComment(printer, descriptor_); printer->Print(variables_, - "$deprecation$public Builder add$capitalized_name$Bytes(\n" + "$deprecation$public Builder ${$add$capitalized_name$Bytes$}$(\n" " com.google.protobuf.ByteString value) {\n" " copyOnWrite();\n" " instance.add$capitalized_name$Bytes(value);\n" " return this;\n" "}\n"); + printer->Annotate("{", "}", descriptor_); } void RepeatedImmutableStringFieldLiteGenerator:: @@ -787,14 +825,14 @@ void RepeatedImmutableStringFieldLiteGenerator:: GenerateParsingCode(io::Printer* printer) const { if (CheckUtf8(descriptor_)) { printer->Print(variables_, - "String s = input.readStringRequireUtf8();\n"); + "java.lang.String s = input.readStringRequireUtf8();\n"); } else { // Lite runtime should attempt to reduce allocations by attempting to // construct the string directly from the input stream buffer. This avoids // spurious intermediary ByteString allocations, cutting overall allocations // in half. printer->Print(variables_, - "String s = input.readString();\n"); + "java.lang.String s = input.readString();\n"); } printer->Print(variables_, "if (!$is_mutable$) {\n" @@ -868,7 +906,7 @@ GenerateHashCode(io::Printer* printer) const { } string RepeatedImmutableStringFieldLiteGenerator::GetBoxedType() const { - return "String"; + return "java.lang.String"; } } // namespace java diff --git a/src/google/protobuf/compiler/js/js_generator.cc b/src/google/protobuf/compiler/js/js_generator.cc index 7c63e58f..ba078703 100755 --- a/src/google/protobuf/compiler/js/js_generator.cc +++ b/src/google/protobuf/compiler/js/js_generator.cc @@ -143,12 +143,16 @@ bool IsReserved(const string& ident) { return false; } +bool StrEndsWith(StringPiece sp, StringPiece x) { + return sp.size() >= x.size() && sp.substr(sp.size() - x.size()) == x; +} + // Returns a copy of |filename| with any trailing ".protodevel" or ".proto // suffix stripped. // TODO(haberman): Unify with copy in compiler/cpp/internal/helpers.cc. string StripProto(const string& filename) { - const char* suffix = HasSuffixString(filename, ".protodevel") - ? ".protodevel" : ".proto"; + const char* suffix = + StrEndsWith(filename, ".protodevel") ? ".protodevel" : ".proto"; return StripSuffixString(filename, suffix); } @@ -756,8 +760,22 @@ string DoubleToString(double value) { return PostProcessFloat(result); } +// Return true if this is an integral field that should be represented as string +// in JS. +bool IsIntegralFieldWithStringJSType(const FieldDescriptor* field) { + switch (field->cpp_type()) { + case FieldDescriptor::CPPTYPE_INT64: + case FieldDescriptor::CPPTYPE_UINT64: + // The default value of JSType is JS_NORMAL, which behaves the same as + // JS_NUMBER. + return field->options().jstype() == google::protobuf::FieldOptions::JS_STRING; + default: + return false; + } +} + string MaybeNumberString(const FieldDescriptor* field, const string& orig) { - return orig; + return IsIntegralFieldWithStringJSType(field) ? ("\"" + orig + "\"") : orig; } string JSFieldDefault(const FieldDescriptor* field) { @@ -856,7 +874,7 @@ string ProtoTypeName(const GeneratorOptions& options, } string JSIntegerTypeName(const FieldDescriptor* field) { - return "number"; + return IsIntegralFieldWithStringJSType(field) ? "string" : "number"; } string JSStringTypeName(const GeneratorOptions& options, @@ -1033,8 +1051,7 @@ string JSBinaryReaderMethodType(const FieldDescriptor* field) { if (name[0] >= 'a' && name[0] <= 'z') { name[0] = (name[0] - 'a') + 'A'; } - - return name; + return IsIntegralFieldWithStringJSType(field) ? (name + "String") : name; } string JSBinaryReadWriteMethodName(const FieldDescriptor* field, @@ -1244,13 +1261,6 @@ string FieldComments(const FieldDescriptor* field, BytesMode bytes_mode) { " * You should avoid comparisons like {@code val === true/false} in " "those cases.\n"; } - if (field->is_repeated()) { - comments += - " * If you change this array by adding, removing or replacing " - "elements, or if you\n" - " * replace the array itself, then you must call the setter to " - "update it.\n"; - } if (field->type() == FieldDescriptor::TYPE_BYTES && bytes_mode == BYTES_U8) { comments += " * Note that Uint8Array is not supported on all browsers.\n" @@ -1323,7 +1333,7 @@ bool IsExtendable(const Descriptor* desc) { // Returns the max index in the underlying data storage array beyond which the // extension object is used. string GetPivot(const Descriptor* desc) { - static const int kDefaultPivot = (1 << 29); // max field number (29 bits) + static const int kDefaultPivot = 500; // Find the max field number int max_field_number = 0; @@ -1335,7 +1345,7 @@ string GetPivot(const Descriptor* desc) { } int pivot = -1; - if (IsExtendable(desc)) { + if (IsExtendable(desc) || (max_field_number >= kDefaultPivot)) { pivot = ((max_field_number + 1) < kDefaultPivot) ? (max_field_number + 1) : kDefaultPivot; } @@ -1507,6 +1517,10 @@ void Generator::GenerateHeader(const GeneratorOptions& options, printer->Print("/**\n" " * @fileoverview\n" " * @enhanceable\n" + " * @suppress {messageConventions} JS Compiler reports an " + "error if a variable or\n" + " * field starts with 'MSG_' and isn't a translatable " + "message.\n" " * @public\n" " */\n" "// GENERATED CODE -- DO NOT EDIT!\n" @@ -1698,18 +1712,16 @@ void Generator::GenerateRequiresImpl(const GeneratorOptions& options, bool require_jspb, bool require_extension, bool require_map) const { if (require_jspb) { - printer->Print( - "goog.require('jspb.Message');\n" - "goog.require('jspb.BinaryReader');\n" - "goog.require('jspb.BinaryWriter');\n"); + required->insert("jspb.Message"); + required->insert("jspb.BinaryReader"); + required->insert("jspb.BinaryWriter"); } if (require_extension) { - printer->Print("goog.require('jspb.ExtensionFieldBinaryInfo');\n"); - printer->Print( - "goog.require('jspb.ExtensionFieldInfo');\n"); + required->insert("jspb.ExtensionFieldBinaryInfo"); + required->insert("jspb.ExtensionFieldInfo"); } if (require_map) { - printer->Print("goog.require('jspb.Map');\n"); + required->insert("jspb.Map"); } std::set<string>::iterator it; @@ -2037,6 +2049,7 @@ void Generator::GenerateClassToObject(const GeneratorOptions& options, " * http://goto/soy-param-migration\n" " * @param {!$classname$} msg The msg instance to transform.\n" " * @return {!Object}\n" + " * @suppress {unusedLocalVariables} f is only used for nested messages\n" " */\n" "$classname$.toObject = function(includeInstance, msg) {\n" " var f, obj = {", @@ -2125,7 +2138,8 @@ void Generator::GenerateFieldValueExpression(io::Printer* printer, "obj", obj_reference); } } else { - printer->Print("jspb.Message.getField($obj$, $index$)", + printer->Print("jspb.Message.get$cardinality$Field($obj$, $index$)", + "cardinality", field->is_repeated() ? "Repeated" : "", "index", JSFieldIndex(field), "obj", obj_reference); } @@ -2333,7 +2347,6 @@ void GenerateBytesWrapper(const GeneratorOptions& options, "defname", JSGetterName(options, field, BYTES_DEFAULT)); } - void Generator::GenerateClassField(const GeneratorOptions& options, io::Printer* printer, const FieldDescriptor* field) const { @@ -2463,7 +2476,7 @@ void Generator::GenerateClassField(const GeneratorOptions& options, // Simple (primitive) field, either singular or repeated. // TODO(b/26173701): Always use BYTES_DEFAULT for the getter return type; - // at this point we "lie" to non-binary users and tell the the return + // at this point we "lie" to non-binary users and tell the return // type is always base64 string, pending a LSC to migrate to typed getters. BytesMode bytes_mode = field->type() == FieldDescriptor::TYPE_BYTES && !options.binary ? @@ -2910,6 +2923,7 @@ void Generator::GenerateClassSerializeBinary(const GeneratorOptions& options, " * format), writing to the given BinaryWriter.\n" " * @param {!$class$} message\n" " * @param {!jspb.BinaryWriter} writer\n" + " * @suppress {unusedLocalVariables} f is only used for nested messages\n" " */\n" "$class$.serializeBinaryToWriter = function(message, " "writer) {\n" @@ -2982,7 +2996,13 @@ void Generator::GenerateClassSerializeBinaryField( case FieldDescriptor::CPPTYPE_INT64: case FieldDescriptor::CPPTYPE_UINT32: case FieldDescriptor::CPPTYPE_UINT64: { - { + if (IsIntegralFieldWithStringJSType(field)) { + // We can use `parseInt` here even though it will not be precise for + // 64-bit quantities because we are only testing for zero/nonzero, + // and JS numbers (64-bit floating point values, i.e., doubles) are + // integer-precise in the range that includes zero. + printer->Print(" if (parseInt(f, 10) !== 0) {\n"); + } else { printer->Print(" if (f !== 0) {\n"); } break; @@ -3306,7 +3326,8 @@ void Generator::GenerateFile(const GeneratorOptions& options, printer->Print( "var $alias$ = require('$file$');\n", "alias", ModuleAlias(name), - "file", GetRootPath(file->name(), name) + GetJSFilename(options, name)); + "file", + GetRootPath(file->name(), name) + GetJSFilename(options, name)); } } diff --git a/src/google/protobuf/compiler/js/well_known_types/any.js b/src/google/protobuf/compiler/js/well_known_types/any.js index 22f18919..d7ca6e3a 100644 --- a/src/google/protobuf/compiler/js/well_known_types/any.js +++ b/src/google/protobuf/compiler/js/well_known_types/any.js @@ -69,7 +69,7 @@ proto.google.protobuf.Any.prototype.pack = function(serialized, name, * the binary data properly. * @param {string} name The expected type name of this message object. * @return {?T} If the name matched the expected name, returns the deserialized - * object, otherwise returns undefined. + * object, otherwise returns null. */ proto.google.protobuf.Any.prototype.unpack = function(deserialize, name) { if (this.getTypeName() == name) { diff --git a/src/google/protobuf/compiler/mock_code_generator.cc b/src/google/protobuf/compiler/mock_code_generator.cc index 0ddb99e5..dfd28330 100644 --- a/src/google/protobuf/compiler/mock_code_generator.cc +++ b/src/google/protobuf/compiler/mock_code_generator.cc @@ -40,6 +40,7 @@ #endif #include <vector> + #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/logging.h> @@ -52,6 +53,7 @@ #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.h> +#include <google/protobuf/text_format.h> #include <google/protobuf/stubs/substitute.h> #include <gtest/gtest.h> @@ -129,11 +131,48 @@ void MockCodeGenerator::ExpectGenerated( } } +namespace { +void CheckSingleAnnotation(const string& expected_file, + const string& expected_text, + const string& file_content, + const GeneratedCodeInfo::Annotation& annotation) { + EXPECT_EQ(expected_file, annotation.source_file()); + ASSERT_GE(file_content.size(), annotation.begin()); + ASSERT_GE(file_content.size(), annotation.end()); + ASSERT_LE(annotation.begin(), annotation.end()); + EXPECT_EQ(expected_text.size(), annotation.end() - annotation.begin()); + EXPECT_EQ(expected_text, + file_content.substr(annotation.begin(), expected_text.size())); +} +} // anonymous namespace + +void MockCodeGenerator::CheckGeneratedAnnotations( + const string& name, const string& file, const string& output_directory) { + string file_content; + GOOGLE_CHECK_OK( + File::GetContents(output_directory + "/" + GetOutputFileName(name, file), + &file_content, true)); + string meta_content; + GOOGLE_CHECK_OK(File::GetContents( + output_directory + "/" + GetOutputFileName(name, file) + ".meta", + &meta_content, true)); + GeneratedCodeInfo annotations; + GOOGLE_CHECK(TextFormat::ParseFromString(meta_content, &annotations)); + ASSERT_EQ(3, annotations.annotation_size()); + CheckSingleAnnotation("first_annotation", "first", file_content, + annotations.annotation(0)); + CheckSingleAnnotation("second_annotation", "second", file_content, + annotations.annotation(1)); + CheckSingleAnnotation("third_annotation", "third", file_content, + annotations.annotation(2)); +} + bool MockCodeGenerator::Generate( const FileDescriptor* file, const string& parameter, GeneratorContext* context, string* error) const { + bool annotate = false; for (int i = 0; i < file->message_type_count(); i++) { if (HasPrefixString(file->message_type(i)->name(), "MockCodeGenerator_")) { string command = StripPrefixString(file->message_type(i)->name(), @@ -162,6 +201,8 @@ bool MockCodeGenerator::Generate( std::cerr << "Saw json_name: " << field_descriptor_proto.has_json_name() << std::endl; abort(); + } else if (command == "Annotate") { + annotate = true; } else if (command == "ShowVersionNumber") { Version compiler_version; context->GetCompilerVersion(&compiler_version); @@ -212,16 +253,40 @@ bool MockCodeGenerator::Generate( google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> output( context->Open(GetOutputFileName(name_, file))); - io::Printer printer(output.get(), '$'); - printer.PrintRaw(GetOutputFileContent(name_, parameter, - file, context)); + GeneratedCodeInfo annotations; + io::AnnotationProtoCollector<GeneratedCodeInfo> annotation_collector( + &annotations); + io::Printer printer(output.get(), '$', + annotate ? &annotation_collector : NULL); + printer.PrintRaw(GetOutputFileContent(name_, parameter, file, context)); + string annotate_suffix = "_annotation"; + if (annotate) { + printer.Print("$p$", "p", "first"); + printer.Annotate("p", "first" + annotate_suffix); + } printer.PrintRaw(kFirstInsertionPoint); + if (annotate) { + printer.Print("$p$", "p", "second"); + printer.Annotate("p", "second" + annotate_suffix); + } printer.PrintRaw(kSecondInsertionPoint); + if (annotate) { + printer.Print("$p$", "p", "third"); + printer.Annotate("p", "third" + annotate_suffix); + } if (printer.failed()) { *error = "MockCodeGenerator detected write error."; return false; } + if (annotate) { + google::protobuf::scoped_ptr<io::ZeroCopyOutputStream> meta_output( + context->Open(GetOutputFileName(name_, file) + ".meta")); + if (!TextFormat::Print(annotations, meta_output.get())) { + *error = "MockCodeGenerator couldn't write .meta"; + return false; + } + } } return true; diff --git a/src/google/protobuf/compiler/mock_code_generator.h b/src/google/protobuf/compiler/mock_code_generator.h index e1665f88..cdd9138c 100644 --- a/src/google/protobuf/compiler/mock_code_generator.h +++ b/src/google/protobuf/compiler/mock_code_generator.h @@ -68,6 +68,8 @@ namespace compiler { // printing "Saw message type MockCodeGenerator_HasSourceCodeInfo: FOO." to // stderr, where FOO is "1" if the supplied FileDescriptorProto has source // code info, and "0" otherwise. +// MockCodeGenerator_Annotate: Generate() will add annotations to its output +// that can later be verified with CheckGeneratedAnnotations. class MockCodeGenerator : public CodeGenerator { public: MockCodeGenerator(const string& name); @@ -88,6 +90,12 @@ class MockCodeGenerator : public CodeGenerator { const string& parsed_file_list, const string& output_directory); + // Checks that the correct text ranges were annotated by the + // MockCodeGenerator_Annotate directive. + static void CheckGeneratedAnnotations(const string& name, + const string& file, + const string& output_directory); + // Get the name of the file which would be written by the given generator. static string GetOutputFileName(const string& generator_name, const FileDescriptor* file); diff --git a/src/google/protobuf/compiler/parser.cc b/src/google/protobuf/compiler/parser.cc index 7a03d42b..23e9e62b 100644 --- a/src/google/protobuf/compiler/parser.cc +++ b/src/google/protobuf/compiler/parser.cc @@ -664,7 +664,7 @@ bool Parser::ParseMessageDefinition( namespace { -const int kMaxExtensionRangeSentinel = -1; +const int kMaxRangeSentinel = -1; bool IsMessageSetWireFormatMessage(const DescriptorProto& message) { const MessageOptions& options = message.options(); @@ -688,12 +688,27 @@ void AdjustExtensionRangesWithMaxEndNumber(DescriptorProto* message) { kint32max : FieldDescriptor::kMaxNumber + 1; for (int i = 0; i < message->extension_range_size(); ++i) { - if (message->extension_range(i).end() == kMaxExtensionRangeSentinel) { + if (message->extension_range(i).end() == kMaxRangeSentinel) { message->mutable_extension_range(i)->set_end(max_extension_number); } } } +// Modifies any reserved ranges that specified 'max' as the end of the +// reserved range, and sets them to the type-specific maximum. The actual max +// tag number can only be determined after all options have been parsed. +void AdjustReservedRangesWithMaxEndNumber(DescriptorProto* message) { + const bool is_message_set = IsMessageSetWireFormatMessage(*message); + const int max_field_number = is_message_set ? + kint32max : + FieldDescriptor::kMaxNumber + 1; + for (int i = 0; i < message->reserved_range_size(); ++i) { + if (message->reserved_range(i).end() == kMaxRangeSentinel) { + message->mutable_reserved_range(i)->set_end(max_field_number); + } + } +} + } // namespace bool Parser::ParseMessageBlock(DescriptorProto* message, @@ -717,6 +732,9 @@ bool Parser::ParseMessageBlock(DescriptorProto* message, if (message->extension_range_size() > 0) { AdjustExtensionRangesWithMaxEndNumber(message); } + if (message->reserved_range_size() > 0) { + AdjustReservedRangesWithMaxEndNumber(message); + } return true; } @@ -1429,6 +1447,8 @@ bool Parser::ParseExtensions(DescriptorProto* message, // Parse the declaration. DO(Consume("extensions")); + int old_range_size = message->extension_range_size(); + do { // Note that kExtensionRangeFieldNumber was already pushed by the parent. LocationRecorder location(extensions_location, @@ -1455,7 +1475,7 @@ bool Parser::ParseExtensions(DescriptorProto* message, // Set to the sentinel value - 1 since we increment the value below. // The actual value of the end of the range should be set with // AdjustExtensionRangesWithMaxEndNumber. - end = kMaxExtensionRangeSentinel - 1; + end = kMaxRangeSentinel - 1; } else { DO(ConsumeInteger(&end, "Expected integer.")); } @@ -1475,12 +1495,36 @@ bool Parser::ParseExtensions(DescriptorProto* message, range->set_end(end); } while (TryConsume(",")); + if (LookingAt("[")) { + LocationRecorder location( + extensions_location, + DescriptorProto::ExtensionRange::kOptionsFieldNumber); + + DO(Consume("[")); + + // Parse extension range options in the first range. + ExtensionRangeOptions* options = + message->mutable_extension_range(old_range_size)->mutable_options(); + do { + DO(ParseOption(options, location, containing_file, OPTION_ASSIGNMENT)); + } while (TryConsume(",")); + + DO(Consume("]")); + + // Then copy the extension range options to all of the other ranges we've + // parsed. + for (int i = old_range_size + 1; i < message->extension_range_size(); i++) { + message->mutable_extension_range(i)->mutable_options() + ->CopyFrom(*options); + } + } + DO(ConsumeEndOfDeclaration(";", &extensions_location)); return true; } -// This is similar to extension range parsing, except that "max" is not -// supported, and accepts field name literals. +// This is similar to extension range parsing, except that it accepts field +// name literals. bool Parser::ParseReserved(DescriptorProto* message, const LocationRecorder& message_location) { // Parse the declaration. @@ -1528,7 +1572,14 @@ bool Parser::ParseReservedNumbers(DescriptorProto* message, if (TryConsume("to")) { LocationRecorder end_location( location, DescriptorProto::ReservedRange::kEndFieldNumber); - DO(ConsumeInteger(&end, "Expected integer.")); + if (TryConsume("max")) { + // Set to the sentinel value - 1 since we increment the value below. + // The actual value of the end of the range should be set with + // AdjustExtensionRangesWithMaxEndNumber. + end = kMaxRangeSentinel - 1; + } else { + DO(ConsumeInteger(&end, "Expected integer.")); + } } else { LocationRecorder end_location( location, DescriptorProto::ReservedRange::kEndFieldNumber); diff --git a/src/google/protobuf/compiler/parser_unittest.cc b/src/google/protobuf/compiler/parser_unittest.cc index d5e31325..97831f71 100644 --- a/src/google/protobuf/compiler/parser_unittest.cc +++ b/src/google/protobuf/compiler/parser_unittest.cc @@ -663,7 +663,7 @@ TEST_F(ParseMessageTest, ReservedRange) { ExpectParsesTo( "message TestMessage {\n" " required int32 foo = 1;\n" - " reserved 2, 15, 9 to 11, 3;\n" + " reserved 2, 15, 9 to 11, 3, 20 to max;\n" "}\n", "message_type {" @@ -673,6 +673,29 @@ TEST_F(ParseMessageTest, ReservedRange) { " reserved_range { start:15 end:16 }" " reserved_range { start:9 end:12 }" " reserved_range { start:3 end:4 }" + " reserved_range { start:20 end:536870912 }" + "}"); +} + +TEST_F(ParseMessageTest, ReservedRangeOnMessageSet) { + ExpectParsesTo( + "message TestMessage {\n" + " option message_set_wire_format = true;\n" + " reserved 20 to max;\n" + "}\n", + + "message_type {" + " name: \"TestMessage\"" + " options {" + " uninterpreted_option {" + " name {" + " name_part: \"message_set_wire_format\"" + " is_extension: false" + " }" + " identifier_value: \"true\"" + " }" + " }" + " reserved_range { start:20 end:2147483647 }" "}"); } @@ -703,6 +726,30 @@ TEST_F(ParseMessageTest, ExtensionRange) { "}"); } +TEST_F(ParseMessageTest, ExtensionRangeWithOptions) { + ExpectParsesTo( + "message TestMessage {\n" + " extensions 10 to 19 [(i) = 5];\n" + "}\n", + + "message_type {" + " name: \"TestMessage\"" + " extension_range {" + " start:10" + " end:20" + " options {" + " uninterpreted_option {" + " name {" + " name_part: \"i\"" + " is_extension: true" + " }" + " positive_int_value: 5" + " }" + " }" + " }" + "}"); +} + TEST_F(ParseMessageTest, CompoundExtensionRange) { ExpectParsesTo( "message TestMessage {\n" @@ -719,6 +766,82 @@ TEST_F(ParseMessageTest, CompoundExtensionRange) { "}"); } +TEST_F(ParseMessageTest, CompoundExtensionRangeWithOptions) { + ExpectParsesTo( + "message TestMessage {\n" + " extensions 2, 15, 9 to 11, 100 to max, 3 [(i) = 5];\n" + "}\n", + + "message_type {" + " name: \"TestMessage\"" + " extension_range {" + " start:2" + " end:3" + " options {" + " uninterpreted_option {" + " name {" + " name_part: \"i\"" + " is_extension: true" + " }" + " positive_int_value: 5" + " }" + " }" + " }" + " extension_range {" + " start:15" + " end:16" + " options {" + " uninterpreted_option {" + " name {" + " name_part: \"i\"" + " is_extension: true" + " }" + " positive_int_value: 5" + " }" + " }" + " }" + " extension_range {" + " start:9" + " end:12" + " options {" + " uninterpreted_option {" + " name {" + " name_part: \"i\"" + " is_extension: true" + " }" + " positive_int_value: 5" + " }" + " }" + " }" + " extension_range {" + " start:100" + " end:536870912" + " options {" + " uninterpreted_option {" + " name {" + " name_part: \"i\"" + " is_extension: true" + " }" + " positive_int_value: 5" + " }" + " }" + " }" + " extension_range {" + " start:3" + " end:4" + " options {" + " uninterpreted_option {" + " name {" + " name_part: \"i\"" + " is_extension: true" + " }" + " positive_int_value: 5" + " }" + " }" + " }" + "}"); +} + TEST_F(ParseMessageTest, LargerMaxForMessageSetWireFormatMessages) { // Messages using the message_set_wire_format option can accept larger // extension numbers, as the numbers are not encoded as int32 field values @@ -1368,12 +1491,12 @@ TEST_F(ParseErrorTest, EnumValueMissingNumber) { // ------------------------------------------------------------------- // Reserved field number errors -TEST_F(ParseErrorTest, ReservedMaxNotAllowed) { +TEST_F(ParseErrorTest, ReservedStandaloneMaxNotAllowed) { ExpectHasErrors( "message Foo {\n" - " reserved 10 to max;\n" + " reserved max;\n" "}\n", - "1:17: Expected integer.\n"); + "1:11: Expected field name or number range.\n"); } TEST_F(ParseErrorTest, ReservedMixNameAndNumber) { diff --git a/src/google/protobuf/compiler/plugin.cc b/src/google/protobuf/compiler/plugin.cc index 3848101d..534b2a73 100644 --- a/src/google/protobuf/compiler/plugin.cc +++ b/src/google/protobuf/compiler/plugin.cc @@ -127,6 +127,7 @@ bool GenerateCode(const CodeGeneratorRequest& request, GeneratorResponseContext context( request.compiler_version(), response, parsed_files); + string error; bool succeeded = generator.GenerateAll( parsed_files, request.parameter(), &context, &error); diff --git a/src/google/protobuf/compiler/plugin.pb.cc b/src/google/protobuf/compiler/plugin.pb.cc index f7dc1b70..6cc96b30 100644 --- a/src/google/protobuf/compiler/plugin.pb.cc +++ b/src/google/protobuf/compiler/plugin.pb.cc @@ -39,23 +39,23 @@ namespace { } // namespace PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField - const TableStruct::entries[] = { + const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField - const TableStruct::aux[] = { + const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ::google::protobuf::internal::AuxillaryParseTableField(), }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const - TableStruct::schema[] = { + TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, }; -const ::google::protobuf::uint32 TableStruct::offsets[] = { +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, _has_bits_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Version, _internal_metadata_), ~0u, // no _extensions_ @@ -103,8 +103,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { 0, ~0u, }; - -static const ::google::protobuf::internal::MigrationSchema schemas[] = { +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { 0, 9, sizeof(Version)}, { 13, 22, sizeof(CodeGeneratorRequest)}, { 26, 34, sizeof(CodeGeneratorResponse_File)}, @@ -140,18 +139,6 @@ void protobuf_RegisterTypes(const ::std::string&) { } } // namespace - -void TableStruct::Shutdown() { - _Version_default_instance_.Shutdown(); - delete file_level_metadata[0].reflection; - _CodeGeneratorRequest_default_instance_.Shutdown(); - delete file_level_metadata[1].reflection; - _CodeGeneratorResponse_File_default_instance_.Shutdown(); - delete file_level_metadata[2].reflection; - _CodeGeneratorResponse_default_instance_.Shutdown(); - delete file_level_metadata[3].reflection; -} - void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -171,7 +158,7 @@ void InitDefaults() { } void AddDescriptorsImpl() { InitDefaults(); - static const char descriptor[] = { + static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { "\n%google/protobuf/compiler/plugin.proto\022" "\030google.protobuf.compiler\032 google/protob" "uf/descriptor.proto\"F\n\007Version\022\r\n\005major\030" @@ -194,14 +181,13 @@ void AddDescriptorsImpl() { ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/compiler/plugin.proto", &protobuf_RegisterTypes); ::google::protobuf::protobuf_google_2fprotobuf_2fdescriptor_2eproto::AddDescriptors(); - ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); } void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -285,11 +271,16 @@ Version* Version::New(::google::protobuf::Arena* arena) const { void Version::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.Version) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + if (has_suffix()) { GOOGLE_DCHECK(!suffix_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*suffix_.UnsafeRawStringPointer())->clear(); } - if (_has_bits_[0 / 32] & 14u) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 14u) { ::memset(&major_, 0, reinterpret_cast<char*>(&patch_) - reinterpret_cast<char*>(&major_) + sizeof(patch_)); } @@ -310,7 +301,7 @@ bool Version::MergePartialFromCodedStream( // optional int32 major = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { set_has_major(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -324,7 +315,7 @@ bool Version::MergePartialFromCodedStream( // optional int32 minor = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { set_has_minor(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -338,7 +329,7 @@ bool Version::MergePartialFromCodedStream( // optional int32 patch = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(24u)) { + static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) { set_has_patch(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -352,7 +343,7 @@ bool Version::MergePartialFromCodedStream( // optional string suffix = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(34u)) { + static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_suffix())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -367,13 +358,11 @@ bool Version::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -421,7 +410,7 @@ void Version::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.compiler.Version) } @@ -461,7 +450,7 @@ void Version::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.Version) return target; @@ -474,7 +463,7 @@ size_t Version::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } if (_has_bits_[0 / 32] & 15u) { // optional string suffix = 4; @@ -577,13 +566,14 @@ void Version::Swap(Version* other) { InternalSwap(other); } void Version::InternalSwap(Version* other) { + using std::swap; suffix_.Swap(&other->suffix_); - std::swap(major_, other->major_); - std::swap(minor_, other->minor_); - std::swap(patch_, other->patch_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(major_, other->major_); + swap(minor_, other->minor_); + swap(patch_, other->patch_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Version::GetMetadata() const { @@ -781,9 +771,7 @@ CodeGeneratorRequest::~CodeGeneratorRequest() { void CodeGeneratorRequest::SharedDtor() { parameter_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != internal_default_instance()) { - delete compiler_version_; - } + delete compiler_version_; } void CodeGeneratorRequest::SetCachedSize(int size) const { @@ -811,14 +799,19 @@ CodeGeneratorRequest* CodeGeneratorRequest::New(::google::protobuf::Arena* arena void CodeGeneratorRequest::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorRequest) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + file_to_generate_.Clear(); proto_file_.Clear(); - if (_has_bits_[0 / 32] & 3u) { - if (has_parameter()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!parameter_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*parameter_.UnsafeRawStringPointer())->clear(); } - if (has_compiler_version()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(compiler_version_ != NULL); compiler_version_->::google::protobuf::compiler::Version::Clear(); } @@ -840,7 +833,7 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream( // repeated string file_to_generate = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->add_file_to_generate())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -857,7 +850,7 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream( // optional string parameter = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_parameter())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -873,7 +866,7 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream( // optional .google.protobuf.compiler.Version compiler_version = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_compiler_version())); } else { @@ -885,7 +878,7 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream( // repeated .google.protobuf.FileDescriptorProto proto_file = 15; case 15: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(122u)) { + static_cast< ::google::protobuf::uint8>(122u /* 122 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_proto_file())); } else { @@ -896,13 +889,11 @@ bool CodeGeneratorRequest::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -957,7 +948,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.compiler.CodeGeneratorRequest) } @@ -1006,7 +997,7 @@ void CodeGeneratorRequest::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.CodeGeneratorRequest) return target; @@ -1019,7 +1010,7 @@ size_t CodeGeneratorRequest::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated string file_to_generate = 1; total_size += 1 * @@ -1123,13 +1114,14 @@ void CodeGeneratorRequest::Swap(CodeGeneratorRequest* other) { InternalSwap(other); } void CodeGeneratorRequest::InternalSwap(CodeGeneratorRequest* other) { + using std::swap; file_to_generate_.InternalSwap(&other->file_to_generate_); proto_file_.InternalSwap(&other->proto_file_); parameter_.Swap(&other->parameter_); - std::swap(compiler_version_, other->compiler_version_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(compiler_version_, other->compiler_version_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata CodeGeneratorRequest::GetMetadata() const { @@ -1317,9 +1309,10 @@ void CodeGeneratorRequest::clear_compiler_version() { clear_has_compiler_version(); } const ::google::protobuf::compiler::Version& CodeGeneratorRequest::compiler_version() const { + const ::google::protobuf::compiler::Version* p = compiler_version_; // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) - return compiler_version_ != NULL ? *compiler_version_ - : *::google::protobuf::compiler::Version::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::compiler::Version*>( + &::google::protobuf::compiler::_Version_default_instance_); } ::google::protobuf::compiler::Version* CodeGeneratorRequest::mutable_compiler_version() { set_has_compiler_version(); @@ -1429,16 +1422,21 @@ CodeGeneratorResponse_File* CodeGeneratorResponse_File::New(::google::protobuf:: void CodeGeneratorResponse_File::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorResponse.File) - if (_has_bits_[0 / 32] & 7u) { - if (has_name()) { + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 7u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*name_.UnsafeRawStringPointer())->clear(); } - if (has_insertion_point()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(!insertion_point_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*insertion_point_.UnsafeRawStringPointer())->clear(); } - if (has_content()) { + if (cached_has_bits & 0x00000004u) { GOOGLE_DCHECK(!content_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*content_.UnsafeRawStringPointer())->clear(); } @@ -1460,7 +1458,7 @@ bool CodeGeneratorResponse_File::MergePartialFromCodedStream( // optional string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -1476,7 +1474,7 @@ bool CodeGeneratorResponse_File::MergePartialFromCodedStream( // optional string insertion_point = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_insertion_point())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -1492,7 +1490,7 @@ bool CodeGeneratorResponse_File::MergePartialFromCodedStream( // optional string content = 15; case 15: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(122u)) { + static_cast< ::google::protobuf::uint8>(122u /* 122 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_content())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -1507,13 +1505,11 @@ bool CodeGeneratorResponse_File::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -1566,7 +1562,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.compiler.CodeGeneratorResponse.File) } @@ -1613,7 +1609,7 @@ void CodeGeneratorResponse_File::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.CodeGeneratorResponse.File) return target; @@ -1626,7 +1622,7 @@ size_t CodeGeneratorResponse_File::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } if (_has_bits_[0 / 32] & 7u) { // optional string name = 1; @@ -1720,12 +1716,13 @@ void CodeGeneratorResponse_File::Swap(CodeGeneratorResponse_File* other) { InternalSwap(other); } void CodeGeneratorResponse_File::InternalSwap(CodeGeneratorResponse_File* other) { + using std::swap; name_.Swap(&other->name_); insertion_point_.Swap(&other->insertion_point_); content_.Swap(&other->content_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata CodeGeneratorResponse_File::GetMetadata() const { @@ -1995,6 +1992,10 @@ CodeGeneratorResponse* CodeGeneratorResponse::New(::google::protobuf::Arena* are void CodeGeneratorResponse::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.compiler.CodeGeneratorResponse) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + file_.Clear(); if (has_error()) { GOOGLE_DCHECK(!error_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); @@ -2017,7 +2018,7 @@ bool CodeGeneratorResponse::MergePartialFromCodedStream( // optional string error = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_error())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -2033,7 +2034,7 @@ bool CodeGeneratorResponse::MergePartialFromCodedStream( // repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; case 15: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(122u)) { + static_cast< ::google::protobuf::uint8>(122u /* 122 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_file())); } else { @@ -2044,13 +2045,11 @@ bool CodeGeneratorResponse::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -2089,7 +2088,7 @@ void CodeGeneratorResponse::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.compiler.CodeGeneratorResponse) } @@ -2121,7 +2120,7 @@ void CodeGeneratorResponse::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.compiler.CodeGeneratorResponse) return target; @@ -2134,7 +2133,7 @@ size_t CodeGeneratorResponse::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.compiler.CodeGeneratorResponse.File file = 15; { @@ -2213,11 +2212,12 @@ void CodeGeneratorResponse::Swap(CodeGeneratorResponse* other) { InternalSwap(other); } void CodeGeneratorResponse::InternalSwap(CodeGeneratorResponse* other) { + using std::swap; file_.InternalSwap(&other->file_); error_.Swap(&other->error_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata CodeGeneratorResponse::GetMetadata() const { diff --git a/src/google/protobuf/compiler/plugin.pb.h b/src/google/protobuf/compiler/plugin.pb.h index 4f8befb6..cce28936 100644 --- a/src/google/protobuf/compiler/plugin.pb.h +++ b/src/google/protobuf/compiler/plugin.pb.h @@ -39,81 +39,6 @@ #endif namespace google { namespace protobuf { -class DescriptorProto; -class DescriptorProtoDefaultTypeInternal; -LIBPROTOC_EXPORT extern DescriptorProtoDefaultTypeInternal _DescriptorProto_default_instance_; -class DescriptorProto_ExtensionRange; -class DescriptorProto_ExtensionRangeDefaultTypeInternal; -LIBPROTOC_EXPORT extern DescriptorProto_ExtensionRangeDefaultTypeInternal _DescriptorProto_ExtensionRange_default_instance_; -class DescriptorProto_ReservedRange; -class DescriptorProto_ReservedRangeDefaultTypeInternal; -LIBPROTOC_EXPORT extern DescriptorProto_ReservedRangeDefaultTypeInternal _DescriptorProto_ReservedRange_default_instance_; -class EnumDescriptorProto; -class EnumDescriptorProtoDefaultTypeInternal; -LIBPROTOC_EXPORT extern EnumDescriptorProtoDefaultTypeInternal _EnumDescriptorProto_default_instance_; -class EnumOptions; -class EnumOptionsDefaultTypeInternal; -LIBPROTOC_EXPORT extern EnumOptionsDefaultTypeInternal _EnumOptions_default_instance_; -class EnumValueDescriptorProto; -class EnumValueDescriptorProtoDefaultTypeInternal; -LIBPROTOC_EXPORT extern EnumValueDescriptorProtoDefaultTypeInternal _EnumValueDescriptorProto_default_instance_; -class EnumValueOptions; -class EnumValueOptionsDefaultTypeInternal; -LIBPROTOC_EXPORT extern EnumValueOptionsDefaultTypeInternal _EnumValueOptions_default_instance_; -class FieldDescriptorProto; -class FieldDescriptorProtoDefaultTypeInternal; -LIBPROTOC_EXPORT extern FieldDescriptorProtoDefaultTypeInternal _FieldDescriptorProto_default_instance_; -class FieldOptions; -class FieldOptionsDefaultTypeInternal; -LIBPROTOC_EXPORT extern FieldOptionsDefaultTypeInternal _FieldOptions_default_instance_; -class FileDescriptorProto; -class FileDescriptorProtoDefaultTypeInternal; -LIBPROTOC_EXPORT extern FileDescriptorProtoDefaultTypeInternal _FileDescriptorProto_default_instance_; -class FileDescriptorSet; -class FileDescriptorSetDefaultTypeInternal; -LIBPROTOC_EXPORT extern FileDescriptorSetDefaultTypeInternal _FileDescriptorSet_default_instance_; -class FileOptions; -class FileOptionsDefaultTypeInternal; -LIBPROTOC_EXPORT extern FileOptionsDefaultTypeInternal _FileOptions_default_instance_; -class GeneratedCodeInfo; -class GeneratedCodeInfoDefaultTypeInternal; -LIBPROTOC_EXPORT extern GeneratedCodeInfoDefaultTypeInternal _GeneratedCodeInfo_default_instance_; -class GeneratedCodeInfo_Annotation; -class GeneratedCodeInfo_AnnotationDefaultTypeInternal; -LIBPROTOC_EXPORT extern GeneratedCodeInfo_AnnotationDefaultTypeInternal _GeneratedCodeInfo_Annotation_default_instance_; -class MessageOptions; -class MessageOptionsDefaultTypeInternal; -LIBPROTOC_EXPORT extern MessageOptionsDefaultTypeInternal _MessageOptions_default_instance_; -class MethodDescriptorProto; -class MethodDescriptorProtoDefaultTypeInternal; -LIBPROTOC_EXPORT extern MethodDescriptorProtoDefaultTypeInternal _MethodDescriptorProto_default_instance_; -class MethodOptions; -class MethodOptionsDefaultTypeInternal; -LIBPROTOC_EXPORT extern MethodOptionsDefaultTypeInternal _MethodOptions_default_instance_; -class OneofDescriptorProto; -class OneofDescriptorProtoDefaultTypeInternal; -LIBPROTOC_EXPORT extern OneofDescriptorProtoDefaultTypeInternal _OneofDescriptorProto_default_instance_; -class OneofOptions; -class OneofOptionsDefaultTypeInternal; -LIBPROTOC_EXPORT extern OneofOptionsDefaultTypeInternal _OneofOptions_default_instance_; -class ServiceDescriptorProto; -class ServiceDescriptorProtoDefaultTypeInternal; -LIBPROTOC_EXPORT extern ServiceDescriptorProtoDefaultTypeInternal _ServiceDescriptorProto_default_instance_; -class ServiceOptions; -class ServiceOptionsDefaultTypeInternal; -LIBPROTOC_EXPORT extern ServiceOptionsDefaultTypeInternal _ServiceOptions_default_instance_; -class SourceCodeInfo; -class SourceCodeInfoDefaultTypeInternal; -LIBPROTOC_EXPORT extern SourceCodeInfoDefaultTypeInternal _SourceCodeInfo_default_instance_; -class SourceCodeInfo_Location; -class SourceCodeInfo_LocationDefaultTypeInternal; -LIBPROTOC_EXPORT extern SourceCodeInfo_LocationDefaultTypeInternal _SourceCodeInfo_Location_default_instance_; -class UninterpretedOption; -class UninterpretedOptionDefaultTypeInternal; -LIBPROTOC_EXPORT extern UninterpretedOptionDefaultTypeInternal _UninterpretedOption_default_instance_; -class UninterpretedOption_NamePart; -class UninterpretedOption_NamePartDefaultTypeInternal; -LIBPROTOC_EXPORT extern UninterpretedOption_NamePartDefaultTypeInternal _UninterpretedOption_NamePart_default_instance_; namespace compiler { class CodeGeneratorRequest; class CodeGeneratorRequestDefaultTypeInternal; @@ -142,8 +67,9 @@ struct LIBPROTOC_EXPORT TableStruct { static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; static void InitDefaultsImpl(); - static void Shutdown(); }; void LIBPROTOC_EXPORT AddDescriptors(); void LIBPROTOC_EXPORT InitDefaults(); @@ -162,11 +88,24 @@ class LIBPROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_ CopyFrom(from); return *this; } + #if LANG_CXX11 + Version(Version&& from) noexcept + : Version() { + *this = ::std::move(from); + } + inline Version& operator=(Version&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -182,6 +121,9 @@ class LIBPROTOC_EXPORT Version : public ::google::protobuf::Message /* @@protoc_ 0; void Swap(Version* other); + friend void swap(Version& a, Version& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -292,11 +234,24 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message CopyFrom(from); return *this; } + #if LANG_CXX11 + CodeGeneratorRequest(CodeGeneratorRequest&& from) noexcept + : CodeGeneratorRequest() { + *this = ::std::move(from); + } + inline CodeGeneratorRequest& operator=(CodeGeneratorRequest&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -312,6 +267,9 @@ class LIBPROTOC_EXPORT CodeGeneratorRequest : public ::google::protobuf::Message 1; void Swap(CodeGeneratorRequest* other); + friend void swap(CodeGeneratorRequest& a, CodeGeneratorRequest& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -440,11 +398,24 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M CopyFrom(from); return *this; } + #if LANG_CXX11 + CodeGeneratorResponse_File(CodeGeneratorResponse_File&& from) noexcept + : CodeGeneratorResponse_File() { + *this = ::std::move(from); + } + inline CodeGeneratorResponse_File& operator=(CodeGeneratorResponse_File&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -460,6 +431,9 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse_File : public ::google::protobuf::M 2; void Swap(CodeGeneratorResponse_File* other); + friend void swap(CodeGeneratorResponse_File& a, CodeGeneratorResponse_File& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -576,11 +550,24 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag CopyFrom(from); return *this; } + #if LANG_CXX11 + CodeGeneratorResponse(CodeGeneratorResponse&& from) noexcept + : CodeGeneratorResponse() { + *this = ::std::move(from); + } + inline CodeGeneratorResponse& operator=(CodeGeneratorResponse&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -596,6 +583,9 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag 3; void Swap(CodeGeneratorResponse* other); + friend void swap(CodeGeneratorResponse& a, CodeGeneratorResponse& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -684,6 +674,10 @@ class LIBPROTOC_EXPORT CodeGeneratorResponse : public ::google::protobuf::Messag // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ // Version // optional int32 major = 1; @@ -1002,9 +996,10 @@ inline void CodeGeneratorRequest::clear_compiler_version() { clear_has_compiler_version(); } inline const ::google::protobuf::compiler::Version& CodeGeneratorRequest::compiler_version() const { + const ::google::protobuf::compiler::Version* p = compiler_version_; // @@protoc_insertion_point(field_get:google.protobuf.compiler.CodeGeneratorRequest.compiler_version) - return compiler_version_ != NULL ? *compiler_version_ - : *::google::protobuf::compiler::Version::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::compiler::Version*>( + &::google::protobuf::compiler::_Version_default_instance_); } inline ::google::protobuf::compiler::Version* CodeGeneratorRequest::mutable_compiler_version() { set_has_compiler_version(); @@ -1322,6 +1317,9 @@ CodeGeneratorResponse::file() const { return file_; } +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // ------------------------------------------------------------------- diff --git a/src/google/protobuf/compiler/plugin.proto b/src/google/protobuf/compiler/plugin.proto index f04dc73c..5b557452 100644 --- a/src/google/protobuf/compiler/plugin.proto +++ b/src/google/protobuf/compiler/plugin.proto @@ -91,6 +91,7 @@ message CodeGeneratorRequest { // The version number of protocol compiler. optional Version compiler_version = 3; + } // The plugin writes an encoded CodeGeneratorResponse to stdout. diff --git a/src/google/protobuf/compiler/python/python_generator.cc b/src/google/protobuf/compiler/python/python_generator.cc index 21a7e158..97769835 100644 --- a/src/google/protobuf/compiler/python/python_generator.cc +++ b/src/google/protobuf/compiler/python/python_generator.cc @@ -63,11 +63,12 @@ #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/stringprintf.h> #include <google/protobuf/io/printer.h> -#include <google/protobuf/descriptor.h> #include <google/protobuf/io/zero_copy_stream.h> +#include <google/protobuf/descriptor.h> #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> + namespace google { namespace protobuf { namespace compiler { @@ -75,12 +76,21 @@ namespace python { namespace { +// Reimplemented here because we can't bring in +// absl/strings/string_view_utils.h because it needs C++11. +bool StrStartsWith(StringPiece sp, StringPiece x) { + return sp.size() >= x.size() && sp.substr(0, x.size()) == x; +} +bool StrEndsWith(StringPiece sp, StringPiece x) { + return sp.size() >= x.size() && sp.substr(sp.size() - x.size()) == x; +} + // Returns a copy of |filename| with any trailing ".protodevel" or ".proto // suffix stripped. // TODO(robinson): Unify with copy in compiler/cpp/internal/helpers.cc. string StripProto(const string& filename) { - const char* suffix = HasSuffixString(filename, ".protodevel") - ? ".protodevel" : ".proto"; + const char* suffix = + StrEndsWith(filename, ".protodevel") ? ".protodevel" : ".proto"; return StripSuffixString(filename, suffix); } @@ -350,7 +360,9 @@ bool Generator::Generate(const FileDescriptor* file, // can only be successfully parsed after we register corresponding // extensions. Therefore we parse all options again here to recognize // custom options that may be unknown when we define the descriptors. + // This does not apply to services because they are not used by extensions. FixAllDescriptorOptions(); + PrintServiceDescriptors(); if (HasGenericServices(file)) { PrintServices(); } @@ -562,9 +574,16 @@ void Generator::PrintMessageDescriptors() const { } } -void Generator::PrintServices() const { +void Generator::PrintServiceDescriptors() const { for (int i = 0; i < file_->service_count(); ++i) { PrintServiceDescriptor(*file_->service(i)); + AddServiceToFileDescriptor(*file_->service(i)); + printer_->Print("\n"); + } +} + +void Generator::PrintServices() const { + for (int i = 0; i < file_->service_count(); ++i) { PrintServiceClass(*file_->service(i)); PrintServiceStub(*file_->service(i)); printer_->Print("\n"); @@ -628,7 +647,10 @@ void Generator::PrintServiceDescriptor( } printer_->Outdent(); - printer_->Print("])\n\n"); + printer_->Print("])\n"); + printer_->Print("_sym_db.RegisterServiceDescriptor($name$)\n", "name", + service_name); + printer_->Print("\n"); } @@ -887,6 +909,18 @@ void Generator::AddMessageToFileDescriptor(const Descriptor& descriptor) const { printer_->Print(m, file_descriptor_template); } +void Generator::AddServiceToFileDescriptor( + const ServiceDescriptor& descriptor) const { + std::map<string, string> m; + m["descriptor_name"] = kDescriptorKey; + m["service_name"] = descriptor.name(); + m["service_descriptor_name"] = ModuleLevelServiceDescriptorName(descriptor); + const char file_descriptor_template[] = + "$descriptor_name$.services_by_name['$service_name$'] = " + "$service_descriptor_name$\n"; + printer_->Print(m, file_descriptor_template); +} + void Generator::AddEnumToFileDescriptor( const EnumDescriptor& descriptor) const { std::map<string, string> m; diff --git a/src/google/protobuf/compiler/python/python_generator.h b/src/google/protobuf/compiler/python/python_generator.h index 594260af..2b5a028b 100644 --- a/src/google/protobuf/compiler/python/python_generator.h +++ b/src/google/protobuf/compiler/python/python_generator.h @@ -112,6 +112,7 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { void AddMessageToFileDescriptor(const Descriptor& descriptor) const; void AddEnumToFileDescriptor(const EnumDescriptor& descriptor) const; void AddExtensionToFileDescriptor(const FieldDescriptor& descriptor) const; + void AddServiceToFileDescriptor(const ServiceDescriptor& descriptor) const; string FieldReferencingExpression(const Descriptor* containing_type, const FieldDescriptor& field, const string& python_dict_name) const; @@ -126,11 +127,12 @@ class LIBPROTOC_EXPORT Generator : public CodeGenerator { void FixForeignFieldsInNestedExtensions(const Descriptor& descriptor) const; void PrintServices() const; + void PrintServiceDescriptors() const; void PrintServiceDescriptor(const ServiceDescriptor& descriptor) const; void PrintServiceClass(const ServiceDescriptor& descriptor) const; void PrintServiceStub(const ServiceDescriptor& descriptor) const; void PrintDescriptorKeyAndModuleName( - const ServiceDescriptor& descriptor) const ; + const ServiceDescriptor& descriptor) const; void PrintEnumValueDescriptor(const EnumValueDescriptor& descriptor) const; string OptionsValue(const string& class_name, diff --git a/src/google/protobuf/compiler/subprocess.cc b/src/google/protobuf/compiler/subprocess.cc index 933450fa..afe48774 100644 --- a/src/google/protobuf/compiler/subprocess.cc +++ b/src/google/protobuf/compiler/subprocess.cc @@ -47,7 +47,6 @@ #include <google/protobuf/message.h> #include <google/protobuf/stubs/substitute.h> - namespace google { namespace protobuf { namespace compiler { @@ -347,7 +346,6 @@ void Subprocess::Start(const string& program, SearchMode search_mode) { bool Subprocess::Communicate(const Message& input, Message* output, string* error) { - GOOGLE_CHECK_NE(child_stdin_, -1) << "Must call Start() first."; // The "sighandler_t" typedef is GNU-specific, so define our own. diff --git a/src/google/protobuf/compiler/subprocess.h b/src/google/protobuf/compiler/subprocess.h index 25138631..9d980b06 100644 --- a/src/google/protobuf/compiler/subprocess.h +++ b/src/google/protobuf/compiler/subprocess.h @@ -44,7 +44,6 @@ #include <string> - namespace google { namespace protobuf { diff --git a/src/google/protobuf/compiler/zip_output_unittest.sh b/src/google/protobuf/compiler/zip_output_unittest.sh index 6fc7136d..8cd80e38 100755 --- a/src/google/protobuf/compiler/zip_output_unittest.sh +++ b/src/google/protobuf/compiler/zip_output_unittest.sh @@ -41,6 +41,8 @@ fail() { TEST_TMPDIR=. PROTOC=./protoc +JAR=jar +UNZIP=unzip echo ' syntax = "proto2"; @@ -57,35 +59,32 @@ $PROTOC \ || fail 'protoc failed.' echo "Testing output to zip..." -if unzip -h > /dev/null; then - unzip -t $TEST_TMPDIR/testzip.zip > $TEST_TMPDIR/testzip.list || fail 'unzip failed.' +$UNZIP -t $TEST_TMPDIR/testzip.zip > $TEST_TMPDIR/testzip.list || fail 'unzip failed.' - grep 'testing: testzip\.pb\.cc *OK$' $TEST_TMPDIR/testzip.list > /dev/null \ - || fail 'testzip.pb.cc not found in output zip.' - grep 'testing: testzip\.pb\.h *OK$' $TEST_TMPDIR/testzip.list > /dev/null \ - || fail 'testzip.pb.h not found in output zip.' - grep 'testing: testzip_pb2\.py *OK$' $TEST_TMPDIR/testzip.list > /dev/null \ - || fail 'testzip_pb2.py not found in output zip.' - grep -i 'manifest' $TEST_TMPDIR/testzip.list > /dev/null \ - && fail 'Zip file contained manifest.' -else - echo "Warning: 'unzip' command not available. Skipping test." -fi +grep 'testing: testzip\.pb\.cc *OK$' $TEST_TMPDIR/testzip.list > /dev/null \ + || fail 'testzip.pb.cc not found in output zip.' +grep 'testing: testzip\.pb\.h *OK$' $TEST_TMPDIR/testzip.list > /dev/null \ + || fail 'testzip.pb.h not found in output zip.' +grep 'testing: testzip_pb2\.py *OK$' $TEST_TMPDIR/testzip.list > /dev/null \ + || fail 'testzip_pb2.py not found in output zip.' +grep -i 'manifest' $TEST_TMPDIR/testzip.list > /dev/null \ + && fail 'Zip file contained manifest.' echo "Testing output to jar..." -if jar c $TEST_TMPDIR/testzip.proto > /dev/null; then - jar tf $TEST_TMPDIR/testzip.jar > $TEST_TMPDIR/testzip.list || fail 'jar failed.' +$JAR tf $TEST_TMPDIR/testzip.jar > $TEST_TMPDIR/testzip.list || fail 'jar failed.' - grep '^test/jar/Foo\.java$' $TEST_TMPDIR/testzip.list > /dev/null \ - || fail 'Foo.java not found in output jar.' - grep '^test/jar/Bar\.java$' $TEST_TMPDIR/testzip.list > /dev/null \ - || fail 'Bar.java not found in output jar.' - grep '^test/jar/Outer\.java$' $TEST_TMPDIR/testzip.list > /dev/null \ - || fail 'Outer.java not found in output jar.' - grep '^META-INF/MANIFEST\.MF$' $TEST_TMPDIR/testzip.list > /dev/null \ - || fail 'Manifest not found in output jar.' -else - echo "Warning: 'jar' command not available. Skipping test." +# Check that -interface.jar timestamps are normalized: +if [[ "$(TZ=UTC $JAR tvf $TEST_TMPDIR/testzip.jar)" != *'Tue Jan 01 00:00:00 UTC 1980'* ]]; then + fail 'Zip did not contain normalized timestamps' fi +grep '^test/jar/Foo\.java$' $TEST_TMPDIR/testzip.list > /dev/null \ + || fail 'Foo.java not found in output jar.' +grep '^test/jar/Bar\.java$' $TEST_TMPDIR/testzip.list > /dev/null \ + || fail 'Bar.java not found in output jar.' +grep '^test/jar/Outer\.java$' $TEST_TMPDIR/testzip.list > /dev/null \ + || fail 'Outer.java not found in output jar.' +grep '^META-INF/MANIFEST\.MF$' $TEST_TMPDIR/testzip.list > /dev/null \ + || fail 'Manifest not found in output jar.' + echo PASS diff --git a/src/google/protobuf/compiler/zip_writer.cc b/src/google/protobuf/compiler/zip_writer.cc index 458cced2..1799af6a 100644 --- a/src/google/protobuf/compiler/zip_writer.cc +++ b/src/google/protobuf/compiler/zip_writer.cc @@ -70,6 +70,10 @@ namespace google { namespace protobuf { namespace compiler { +// January 1, 1980 as a DOS date. +// see https://msdn.microsoft.com/en-us/library/9kkf9tah.aspx +static const uint16 kDosEpoch = 1 << 5 | 1; + static const uint32 kCRC32Table[256] = { 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, @@ -154,7 +158,7 @@ bool ZipWriter::Write(const string& filename, const string& contents) { WriteShort(&output, 0); // flags WriteShort(&output, 0); // compression method: stored WriteShort(&output, 0); // last modified time - WriteShort(&output, 0); // last modified date + WriteShort(&output, kDosEpoch); // last modified date output.WriteLittleEndian32(info.crc32); // crc-32 output.WriteLittleEndian32(info.size); // compressed size output.WriteLittleEndian32(info.size); // uncompressed size @@ -185,7 +189,7 @@ bool ZipWriter::WriteDirectory() { WriteShort(&output, 0); // flags WriteShort(&output, 0); // compression method: stored WriteShort(&output, 0); // last modified time - WriteShort(&output, 0); // last modified date + WriteShort(&output, kDosEpoch); // last modified date output.WriteLittleEndian32(crc32); // crc-32 output.WriteLittleEndian32(size); // compressed size output.WriteLittleEndian32(size); // uncompressed size diff --git a/src/google/protobuf/descriptor.cc b/src/google/protobuf/descriptor.cc index 6a807926..89b37ee3 100644 --- a/src/google/protobuf/descriptor.cc +++ b/src/google/protobuf/descriptor.cc @@ -44,25 +44,26 @@ #include <algorithm> #include <limits> +#include <google/protobuf/stubs/common.h> +#include <google/protobuf/stubs/logging.h> +#include <google/protobuf/stubs/mutex.h> +#include <google/protobuf/stubs/once.h> +#include <google/protobuf/stubs/stringprintf.h> +#include <google/protobuf/stubs/strutil.h> +#include <google/protobuf/io/strtod.h> +#include <google/protobuf/io/coded_stream.h> +#include <google/protobuf/io/tokenizer.h> +#include <google/protobuf/io/zero_copy_stream_impl.h> +#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/descriptor.h> #include <google/protobuf/descriptor_database.h> -#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/dynamic_message.h> #include <google/protobuf/generated_message_util.h> #include <google/protobuf/text_format.h> #include <google/protobuf/unknown_field_set.h> #include <google/protobuf/wire_format.h> -#include <google/protobuf/io/strtod.h> -#include <google/protobuf/io/coded_stream.h> -#include <google/protobuf/io/tokenizer.h> -#include <google/protobuf/io/zero_copy_stream_impl.h> -#include <google/protobuf/stubs/common.h> -#include <google/protobuf/stubs/logging.h> -#include <google/protobuf/stubs/mutex.h> -#include <google/protobuf/stubs/once.h> -#include <google/protobuf/stubs/stringprintf.h> -#include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> + #include <google/protobuf/stubs/map_util.h> #include <google/protobuf/stubs/stl_util.h> @@ -1953,6 +1954,10 @@ void Descriptor::CopyTo(DescriptorProto* proto) const { DescriptorProto::ExtensionRange* range = proto->add_extension_range(); range->set_start(extension_range(i)->start); range->set_end(extension_range(i)->end); + const ExtensionRangeOptions* options = extension_range(i)->options_; + if (options != &ExtensionRangeOptions::default_instance()) { + range->mutable_options()->CopyFrom(*options); + } } for (int i = 0; i < extension_count(); i++) { extension(i)->CopyTo(proto->add_extension()); @@ -3203,6 +3208,8 @@ class DescriptorBuilder { void CrossLinkMessage(Descriptor* message, const DescriptorProto& proto); void CrossLinkField(FieldDescriptor* field, const FieldDescriptorProto& proto); + void CrossLinkExtensionRange(Descriptor::ExtensionRange* range, + const DescriptorProto::ExtensionRange& proto); void CrossLinkEnum(EnumDescriptor* enum_type, const EnumDescriptorProto& proto); void CrossLinkEnumValue(EnumValueDescriptor* enum_value, @@ -3382,6 +3389,8 @@ class DescriptorBuilder { void DetectMapConflicts(const Descriptor* message, const DescriptorProto& proto); + void ValidateJSType(FieldDescriptor* field, + const FieldDescriptorProto& proto); }; const FileDescriptor* DescriptorPool::BuildFile( @@ -3509,8 +3518,8 @@ void DescriptorBuilder::AddWarning( bool DescriptorBuilder::IsInPackage(const FileDescriptor* file, const string& package_name) { return HasPrefixString(file->package(), package_name) && - (file->package().size() == package_name.size() || - file->package()[package_name.size()] == '.'); + (file->package().size() == package_name.size() || + file->package()[package_name.size()] == '.'); } void DescriptorBuilder::RecordPublicDependencies(const FileDescriptor* file) { @@ -4776,6 +4785,13 @@ void DescriptorBuilder::BuildExtensionRange( DescriptorPool::ErrorCollector::NUMBER, "Extension range end number must be greater than start number."); } + + if (!proto.has_options()) { + result->options_ = NULL; // Will set to default_instance later. + } else { + AllocateOptionsImpl(parent->full_name(), parent->full_name(), + proto.options(), result); + } } void DescriptorBuilder::BuildReservedRange( @@ -5100,6 +5116,11 @@ void DescriptorBuilder::CrossLinkMessage( CrossLinkField(&message->extensions_[i], proto.extension(i)); } + for (int i = 0; i < message->extension_range_count(); i++) { + CrossLinkExtensionRange(&message->extension_ranges_[i], + proto.extension_range(i)); + } + // Set up field array for each oneof. // First count the number of fields per oneof. @@ -5162,6 +5183,14 @@ void DescriptorBuilder::CrossLinkMessage( } } +void DescriptorBuilder::CrossLinkExtensionRange( + Descriptor::ExtensionRange* range, + const DescriptorProto::ExtensionRange& proto) { + if (range->options_ == NULL) { + range->options_ = &ExtensionRangeOptions::default_instance(); + } +} + void DescriptorBuilder::CrossLinkField( FieldDescriptor* field, const FieldDescriptorProto& proto) { if (field->options_ == NULL) { @@ -5734,6 +5763,8 @@ void DescriptorBuilder::ValidateFieldOptions(FieldDescriptor* field, } } + ValidateJSType(field, proto); + } void DescriptorBuilder::ValidateEnumOptions(EnumDescriptor* enm, @@ -5922,6 +5953,40 @@ void DescriptorBuilder::DetectMapConflicts(const Descriptor* message, } } +void DescriptorBuilder::ValidateJSType(FieldDescriptor* field, + const FieldDescriptorProto& proto) { + FieldOptions::JSType jstype = field->options().jstype(); + // The default is always acceptable. + if (jstype == FieldOptions::JS_NORMAL) { + return; + } + + switch (field->type()) { + // Integral 64-bit types may be represented as JavaScript numbers or + // strings. + case FieldDescriptor::TYPE_UINT64: + case FieldDescriptor::TYPE_INT64: + case FieldDescriptor::TYPE_SINT64: + case FieldDescriptor::TYPE_FIXED64: + case FieldDescriptor::TYPE_SFIXED64: + if (jstype == FieldOptions::JS_STRING || + jstype == FieldOptions::JS_NUMBER) { + return; + } + AddError(field->full_name(), proto, DescriptorPool::ErrorCollector::TYPE, + "Illegal jstype for int64, uint64, sint64, fixed64 " + "or sfixed64 field: " + + FieldOptions_JSType_descriptor()->value(jstype)->name()); + break; + + // No other types permit a jstype option. + default: + AddError(field->full_name(), proto, DescriptorPool::ErrorCollector::TYPE, + "jstype is only allowed on int64, uint64, sint64, fixed64 " + "or sfixed64 fields."); + break; + } +} #undef VALIDATE_OPTIONS_FROM_ARRAY @@ -6663,6 +6728,7 @@ void DescriptorBuilder::LogUnusedDependency(const FileDescriptorProto& proto, annotation_extensions.insert("google.protobuf.FieldOptions"); annotation_extensions.insert("google.protobuf.EnumOptions"); annotation_extensions.insert("google.protobuf.EnumValueOptions"); + annotation_extensions.insert("google.protobuf.EnumValueOptions"); annotation_extensions.insert("google.protobuf.ServiceOptions"); annotation_extensions.insert("google.protobuf.MethodOptions"); annotation_extensions.insert("google.protobuf.StreamOptions"); diff --git a/src/google/protobuf/descriptor.h b/src/google/protobuf/descriptor.h index 7aea7344..57128e6b 100644 --- a/src/google/protobuf/descriptor.h +++ b/src/google/protobuf/descriptor.h @@ -99,6 +99,7 @@ class FieldOptions; class OneofOptions; class EnumOptions; class EnumValueOptions; +class ExtensionRangeOptions; class ServiceOptions; class MethodOptions; class FileOptions; @@ -337,8 +338,12 @@ class LIBPROTOBUF_EXPORT Descriptor { // A range of field numbers which are designated for third-party // extensions. struct ExtensionRange { + typedef ExtensionRangeOptions OptionsType; + int start; // inclusive int end; // exclusive + + const ExtensionRangeOptions* options_; }; // The number of extension ranges in this message type. @@ -440,27 +445,30 @@ class LIBPROTOBUF_EXPORT Descriptor { const Descriptor* containing_type_; const MessageOptions* options_; - // True if this is a placeholder for an unknown type. - bool is_placeholder_; - // True if this is a placeholder and the type name wasn't fully-qualified. - bool is_unqualified_placeholder_; + // These arrays are separated from their sizes to minimize padding on 64-bit. + FieldDescriptor* fields_; + OneofDescriptor* oneof_decls_; + Descriptor* nested_types_; + EnumDescriptor* enum_types_; + ExtensionRange* extension_ranges_; + FieldDescriptor* extensions_; + ReservedRange* reserved_ranges_; + const string** reserved_names_; int field_count_; - FieldDescriptor* fields_; int oneof_decl_count_; - OneofDescriptor* oneof_decls_; int nested_type_count_; - Descriptor* nested_types_; int enum_type_count_; - EnumDescriptor* enum_types_; int extension_range_count_; - ExtensionRange* extension_ranges_; int extension_count_; - FieldDescriptor* extensions_; int reserved_range_count_; - ReservedRange* reserved_ranges_; int reserved_name_count_; - const string** reserved_names_; + + // True if this is a placeholder for an unknown type. + bool is_placeholder_; + // True if this is a placeholder and the type name wasn't fully-qualified. + bool is_unqualified_placeholder_; + // IMPORTANT: If you add a new field, make sure to search for all instances // of Allocate<Descriptor>() and AllocateArray<Descriptor>() in descriptor.cc // and update them to initialize the field. @@ -477,6 +485,7 @@ class LIBPROTOBUF_EXPORT Descriptor { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Descriptor); }; + // Describes a single field of a message. To get the descriptor for a given // field, first get the Descriptor for the message in which it is defined, // then call Descriptor::FindFieldByName(). To get a FieldDescriptor for @@ -736,20 +745,21 @@ class LIBPROTOBUF_EXPORT FieldDescriptor { const string* full_name_; const string* lowercase_name_; const string* camelcase_name_; - // Whether the user has specified the json_name field option in the .proto - // file. - bool has_json_name_; // If has_json_name_ is true, it's the value specified by the user. // Otherwise, it has the same value as camelcase_name_. const string* json_name_; const FileDescriptor* file_; - int number_; GoogleOnceDynamic* type_once_; static void TypeOnceInit(const FieldDescriptor* to_init); void InternalTypeOnceInit() const; mutable Type type_; Label label_; + bool has_default_value_; + // Whether the user has specified the json_name field option in the .proto + // file. + bool has_json_name_; bool is_extension_; + int number_; int index_in_oneof_; const Descriptor* containing_type_; const OneofDescriptor* containing_oneof_; @@ -763,7 +773,6 @@ class LIBPROTOBUF_EXPORT FieldDescriptor { // of Allocate<FieldDescriptor>() and AllocateArray<FieldDescriptor>() in // descriptor.cc and update them to initialize the field. - bool has_default_value_; union { int32 default_value_int32_; int64 default_value_int64_; @@ -794,6 +803,7 @@ class LIBPROTOBUF_EXPORT FieldDescriptor { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldDescriptor); }; + // Describes a oneof defined in a message type. class LIBPROTOBUF_EXPORT OneofDescriptor { public: @@ -803,6 +813,8 @@ class LIBPROTOBUF_EXPORT OneofDescriptor { // Index of this oneof within the message's oneof array. int index() const; + // The .proto file in which this oneof was defined. Never NULL. + const FileDescriptor* file() const; // The Descriptor for the message containing this oneof. const Descriptor* containing_type() const; @@ -998,6 +1010,8 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptor { // with C++ scoping rules for enums. const string& full_name() const; + // The .proto file in which this value was defined. Never NULL. + const FileDescriptor* file() const; // The type of this value. Never NULL. const EnumDescriptor* type() const; @@ -1122,8 +1136,8 @@ class LIBPROTOBUF_EXPORT ServiceDescriptor { const string* full_name_; const FileDescriptor* file_; const ServiceOptions* options_; - int method_count_; MethodDescriptor* methods_; + int method_count_; // IMPORTANT: If you add a new field, make sure to search for all instances // of Allocate<ServiceDescriptor>() and AllocateArray<ServiceDescriptor>() in // descriptor.cc and update them to initialize the field. @@ -1136,6 +1150,7 @@ class LIBPROTOBUF_EXPORT ServiceDescriptor { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ServiceDescriptor); }; + // Describes an individual service method. To obtain a MethodDescriptor given // a service, first get its ServiceDescriptor, then call // ServiceDescriptor::FindMethodByName(). Use DescriptorPool to construct your @@ -1149,6 +1164,8 @@ class LIBPROTOBUF_EXPORT MethodDescriptor { // Index within the service's Descriptor. int index() const; + // The .proto file in which this method was defined. Never NULL. + const FileDescriptor* file() const; // Gets the service to which this method belongs. Never NULL. const ServiceDescriptor* service() const; @@ -1360,36 +1377,39 @@ class LIBPROTOBUF_EXPORT FileDescriptor { const string* name_; const string* package_; const DescriptorPool* pool_; - int dependency_count_; - mutable const FileDescriptor** dependencies_; - const string** dependencies_names_; GoogleOnceDynamic* dependencies_once_; static void DependenciesOnceInit(const FileDescriptor* to_init); void InternalDependenciesOnceInit() const; + + // These are arranged to minimze padding on 64-bit. + int dependency_count_; int public_dependency_count_; - int* public_dependencies_; int weak_dependency_count_; - int* weak_dependencies_; int message_type_count_; - Descriptor* message_types_; int enum_type_count_; - EnumDescriptor* enum_types_; int service_count_; - ServiceDescriptor* services_; int extension_count_; Syntax syntax_; bool is_placeholder_; - FieldDescriptor* extensions_; - const FileOptions* options_; - - const FileDescriptorTables* tables_; - const SourceCodeInfo* source_code_info_; // Indicates the FileDescriptor is completed building. Used to verify // that type accessor functions that can possibly build a dependent file // aren't called during the process of building the file. bool finished_building_; + mutable const FileDescriptor** dependencies_; + const string** dependencies_names_; + int* public_dependencies_; + int* weak_dependencies_; + Descriptor* message_types_; + EnumDescriptor* enum_types_; + ServiceDescriptor* services_; + FieldDescriptor* extensions_; + const FileOptions* options_; + + const FileDescriptorTables* tables_; + const SourceCodeInfo* source_code_info_; + // IMPORTANT: If you add a new field, make sure to search for all instances // of Allocate<FileDescriptor>() and AllocateArray<FileDescriptor>() in // descriptor.cc and update them to initialize the field. @@ -1408,6 +1428,7 @@ class LIBPROTOBUF_EXPORT FileDescriptor { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FileDescriptor); }; + // =================================================================== // Used to construct descriptors. @@ -1748,12 +1769,13 @@ class LIBPROTOBUF_EXPORT DescriptorPool { bool lazily_build_dependencies_; bool allow_unknown_; bool enforce_weak_; - std::set<string> unused_import_track_files_; bool disallow_enforce_utf8_; + std::set<string> unused_import_track_files_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DescriptorPool); }; + // inline methods ==================================================== // These macros makes this repetitive code more readable. @@ -1949,6 +1971,10 @@ inline int Descriptor::index() const { } } +inline const FileDescriptor* OneofDescriptor::file() const { + return containing_type()->file(); +} + inline int OneofDescriptor::index() const { return static_cast<int>(this - containing_type_->oneof_decls_); } @@ -1961,6 +1987,10 @@ inline int EnumDescriptor::index() const { } } +inline const FileDescriptor* EnumValueDescriptor::file() const { + return type()->file(); +} + inline int EnumValueDescriptor::index() const { return static_cast<int>(this - type_->values_); } @@ -1969,6 +1999,10 @@ inline int ServiceDescriptor::index() const { return static_cast<int>(this - file_->services_); } +inline const FileDescriptor* MethodDescriptor::file() const { + return service()->file(); +} + inline int MethodDescriptor::index() const { return static_cast<int>(this - service_->methods_); } diff --git a/src/google/protobuf/descriptor.pb.cc b/src/google/protobuf/descriptor.pb.cc index 56c395e6..6a3f5f86 100644 --- a/src/google/protobuf/descriptor.pb.cc +++ b/src/google/protobuf/descriptor.pb.cc @@ -29,6 +29,8 @@ class DescriptorProto_ReservedRangeDefaultTypeInternal : public ::google::protob } _DescriptorProto_ReservedRange_default_instance_; class DescriptorProtoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<DescriptorProto> { } _DescriptorProto_default_instance_; +class ExtensionRangeOptionsDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<ExtensionRangeOptions> { +} _ExtensionRangeOptions_default_instance_; class FieldDescriptorProtoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<FieldDescriptorProto> { } _FieldDescriptorProto_default_instance_; class OneofDescriptorProtoDefaultTypeInternal : public ::google::protobuf::internal::ExplicitlyConstructed<OneofDescriptorProto> { @@ -75,22 +77,23 @@ namespace protobuf_google_2fprotobuf_2fdescriptor_2eproto { namespace { -::google::protobuf::Metadata file_level_metadata[25]; +::google::protobuf::Metadata file_level_metadata[26]; const ::google::protobuf::EnumDescriptor* file_level_enum_descriptors[6]; } // namespace PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField - const TableStruct::entries[] = { + const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField - const TableStruct::aux[] = { + const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ::google::protobuf::internal::AuxillaryParseTableField(), }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const - TableStruct::schema[] = { + TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { + { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, @@ -118,7 +121,7 @@ PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const { NULL, NULL, 0, -1, -1, false }, }; -const ::google::protobuf::uint32 TableStruct::offsets[] = { +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, _has_bits_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FileDescriptorSet, _internal_metadata_), ~0u, // no _extensions_ @@ -162,8 +165,10 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, start_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, end_), - 0, + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ExtensionRange, options_), 1, + 2, + 0, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, _has_bits_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DescriptorProto_ReservedRange, _internal_metadata_), ~0u, // no _extensions_ @@ -198,6 +203,13 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { 1, ~0u, ~0u, + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ExtensionRangeOptions, _has_bits_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ExtensionRangeOptions, _internal_metadata_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ExtensionRangeOptions, _extensions_), + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ExtensionRangeOptions, uninterpreted_option_), + ~0u, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, _has_bits_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldDescriptorProto, _internal_metadata_), ~0u, // no _extensions_ @@ -473,33 +485,33 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(GeneratedCodeInfo, annotation_), ~0u, }; - -static const ::google::protobuf::internal::MigrationSchema schemas[] = { +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { 0, 6, sizeof(FileDescriptorSet)}, { 7, 24, sizeof(FileDescriptorProto)}, - { 36, 43, sizeof(DescriptorProto_ExtensionRange)}, - { 45, 52, sizeof(DescriptorProto_ReservedRange)}, - { 54, 69, sizeof(DescriptorProto)}, - { 79, 94, sizeof(FieldDescriptorProto)}, - { 104, 111, sizeof(OneofDescriptorProto)}, - { 113, 121, sizeof(EnumDescriptorProto)}, - { 124, 132, sizeof(EnumValueDescriptorProto)}, - { 135, 143, sizeof(ServiceDescriptorProto)}, - { 146, 157, sizeof(MethodDescriptorProto)}, - { 163, 185, sizeof(FileOptions)}, - { 202, 212, sizeof(MessageOptions)}, - { 217, 229, sizeof(FieldOptions)}, - { 236, 242, sizeof(OneofOptions)}, - { 243, 251, sizeof(EnumOptions)}, - { 254, 261, sizeof(EnumValueOptions)}, - { 263, 270, sizeof(ServiceOptions)}, - { 272, 280, sizeof(MethodOptions)}, - { 283, 290, sizeof(UninterpretedOption_NamePart)}, - { 292, 304, sizeof(UninterpretedOption)}, - { 311, 321, sizeof(SourceCodeInfo_Location)}, - { 326, 332, sizeof(SourceCodeInfo)}, - { 333, 342, sizeof(GeneratedCodeInfo_Annotation)}, - { 346, 352, sizeof(GeneratedCodeInfo)}, + { 36, 44, sizeof(DescriptorProto_ExtensionRange)}, + { 47, 54, sizeof(DescriptorProto_ReservedRange)}, + { 56, 71, sizeof(DescriptorProto)}, + { 81, 87, sizeof(ExtensionRangeOptions)}, + { 88, 103, sizeof(FieldDescriptorProto)}, + { 113, 120, sizeof(OneofDescriptorProto)}, + { 122, 130, sizeof(EnumDescriptorProto)}, + { 133, 141, sizeof(EnumValueDescriptorProto)}, + { 144, 152, sizeof(ServiceDescriptorProto)}, + { 155, 166, sizeof(MethodDescriptorProto)}, + { 172, 194, sizeof(FileOptions)}, + { 211, 221, sizeof(MessageOptions)}, + { 226, 238, sizeof(FieldOptions)}, + { 245, 251, sizeof(OneofOptions)}, + { 252, 260, sizeof(EnumOptions)}, + { 263, 270, sizeof(EnumValueOptions)}, + { 272, 279, sizeof(ServiceOptions)}, + { 281, 289, sizeof(MethodOptions)}, + { 292, 299, sizeof(UninterpretedOption_NamePart)}, + { 301, 313, sizeof(UninterpretedOption)}, + { 320, 330, sizeof(SourceCodeInfo_Location)}, + { 335, 341, sizeof(SourceCodeInfo)}, + { 342, 351, sizeof(GeneratedCodeInfo_Annotation)}, + { 355, 361, sizeof(GeneratedCodeInfo)}, }; static ::google::protobuf::Message const * const file_default_instances[] = { @@ -508,6 +520,7 @@ static ::google::protobuf::Message const * const file_default_instances[] = { reinterpret_cast<const ::google::protobuf::Message*>(&_DescriptorProto_ExtensionRange_default_instance_), reinterpret_cast<const ::google::protobuf::Message*>(&_DescriptorProto_ReservedRange_default_instance_), reinterpret_cast<const ::google::protobuf::Message*>(&_DescriptorProto_default_instance_), + reinterpret_cast<const ::google::protobuf::Message*>(&_ExtensionRangeOptions_default_instance_), reinterpret_cast<const ::google::protobuf::Message*>(&_FieldDescriptorProto_default_instance_), reinterpret_cast<const ::google::protobuf::Message*>(&_OneofDescriptorProto_default_instance_), reinterpret_cast<const ::google::protobuf::Message*>(&_EnumDescriptorProto_default_instance_), @@ -548,64 +561,10 @@ void protobuf_AssignDescriptorsOnce() { void protobuf_RegisterTypes(const ::std::string&) GOOGLE_ATTRIBUTE_COLD; void protobuf_RegisterTypes(const ::std::string&) { protobuf_AssignDescriptorsOnce(); - ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 25); + ::google::protobuf::internal::RegisterAllTypes(file_level_metadata, 26); } } // namespace - -void TableStruct::Shutdown() { - _FileDescriptorSet_default_instance_.Shutdown(); - delete file_level_metadata[0].reflection; - _FileDescriptorProto_default_instance_.Shutdown(); - delete file_level_metadata[1].reflection; - _DescriptorProto_ExtensionRange_default_instance_.Shutdown(); - delete file_level_metadata[2].reflection; - _DescriptorProto_ReservedRange_default_instance_.Shutdown(); - delete file_level_metadata[3].reflection; - _DescriptorProto_default_instance_.Shutdown(); - delete file_level_metadata[4].reflection; - _FieldDescriptorProto_default_instance_.Shutdown(); - delete file_level_metadata[5].reflection; - _OneofDescriptorProto_default_instance_.Shutdown(); - delete file_level_metadata[6].reflection; - _EnumDescriptorProto_default_instance_.Shutdown(); - delete file_level_metadata[7].reflection; - _EnumValueDescriptorProto_default_instance_.Shutdown(); - delete file_level_metadata[8].reflection; - _ServiceDescriptorProto_default_instance_.Shutdown(); - delete file_level_metadata[9].reflection; - _MethodDescriptorProto_default_instance_.Shutdown(); - delete file_level_metadata[10].reflection; - _FileOptions_default_instance_.Shutdown(); - delete file_level_metadata[11].reflection; - _MessageOptions_default_instance_.Shutdown(); - delete file_level_metadata[12].reflection; - _FieldOptions_default_instance_.Shutdown(); - delete file_level_metadata[13].reflection; - _OneofOptions_default_instance_.Shutdown(); - delete file_level_metadata[14].reflection; - _EnumOptions_default_instance_.Shutdown(); - delete file_level_metadata[15].reflection; - _EnumValueOptions_default_instance_.Shutdown(); - delete file_level_metadata[16].reflection; - _ServiceOptions_default_instance_.Shutdown(); - delete file_level_metadata[17].reflection; - _MethodOptions_default_instance_.Shutdown(); - delete file_level_metadata[18].reflection; - _UninterpretedOption_NamePart_default_instance_.Shutdown(); - delete file_level_metadata[19].reflection; - _UninterpretedOption_default_instance_.Shutdown(); - delete file_level_metadata[20].reflection; - _SourceCodeInfo_Location_default_instance_.Shutdown(); - delete file_level_metadata[21].reflection; - _SourceCodeInfo_default_instance_.Shutdown(); - delete file_level_metadata[22].reflection; - _GeneratedCodeInfo_Annotation_default_instance_.Shutdown(); - delete file_level_metadata[23].reflection; - _GeneratedCodeInfo_default_instance_.Shutdown(); - delete file_level_metadata[24].reflection; -} - void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -615,6 +574,7 @@ void TableStruct::InitDefaultsImpl() { _DescriptorProto_ExtensionRange_default_instance_.DefaultConstruct(); _DescriptorProto_ReservedRange_default_instance_.DefaultConstruct(); _DescriptorProto_default_instance_.DefaultConstruct(); + _ExtensionRangeOptions_default_instance_.DefaultConstruct(); _FieldDescriptorProto_default_instance_.DefaultConstruct(); _OneofDescriptorProto_default_instance_.DefaultConstruct(); _EnumDescriptorProto_default_instance_.DefaultConstruct(); @@ -639,6 +599,8 @@ void TableStruct::InitDefaultsImpl() { ::google::protobuf::FileOptions::internal_default_instance()); _FileDescriptorProto_default_instance_.get_mutable()->source_code_info_ = const_cast< ::google::protobuf::SourceCodeInfo*>( ::google::protobuf::SourceCodeInfo::internal_default_instance()); + _DescriptorProto_ExtensionRange_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::ExtensionRangeOptions*>( + ::google::protobuf::ExtensionRangeOptions::internal_default_instance()); _DescriptorProto_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::MessageOptions*>( ::google::protobuf::MessageOptions::internal_default_instance()); _FieldDescriptorProto_default_instance_.get_mutable()->options_ = const_cast< ::google::protobuf::FieldOptions*>( @@ -661,7 +623,7 @@ void InitDefaults() { } void AddDescriptorsImpl() { InitDefaults(); - static const char descriptor[] = { + static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { "\n google/protobuf/descriptor.proto\022\017goog" "le.protobuf\"G\n\021FileDescriptorSet\0222\n\004file" "\030\001 \003(\0132$.google.protobuf.FileDescriptorP" @@ -677,7 +639,7 @@ void AddDescriptorsImpl() { "\022-\n\007options\030\010 \001(\0132\034.google.protobuf.File" "Options\0229\n\020source_code_info\030\t \001(\0132\037.goog" "le.protobuf.SourceCodeInfo\022\016\n\006syntax\030\014 \001" - "(\t\"\360\004\n\017DescriptorProto\022\014\n\004name\030\001 \001(\t\0224\n\005" + "(\t\"\251\005\n\017DescriptorProto\022\014\n\004name\030\001 \001(\t\0224\n\005" "field\030\002 \003(\0132%.google.protobuf.FieldDescr" "iptorProto\0228\n\textension\030\006 \003(\0132%.google.p" "rotobuf.FieldDescriptorProto\0225\n\013nested_t" @@ -690,131 +652,134 @@ void AddDescriptorsImpl() { "ions\030\007 \001(\0132\037.google.protobuf.MessageOpti" "ons\022F\n\016reserved_range\030\t \003(\0132..google.pro" "tobuf.DescriptorProto.ReservedRange\022\025\n\rr" - "eserved_name\030\n \003(\t\032,\n\016ExtensionRange\022\r\n\005" - "start\030\001 \001(\005\022\013\n\003end\030\002 \001(\005\032+\n\rReservedRang" - "e\022\r\n\005start\030\001 \001(\005\022\013\n\003end\030\002 \001(\005\"\274\005\n\024FieldD" - "escriptorProto\022\014\n\004name\030\001 \001(\t\022\016\n\006number\030\003" - " \001(\005\022:\n\005label\030\004 \001(\0162+.google.protobuf.Fi" - "eldDescriptorProto.Label\0228\n\004type\030\005 \001(\0162*" - ".google.protobuf.FieldDescriptorProto.Ty" - "pe\022\021\n\ttype_name\030\006 \001(\t\022\020\n\010extendee\030\002 \001(\t\022" - "\025\n\rdefault_value\030\007 \001(\t\022\023\n\013oneof_index\030\t " - "\001(\005\022\021\n\tjson_name\030\n \001(\t\022.\n\007options\030\010 \001(\0132" - "\035.google.protobuf.FieldOptions\"\266\002\n\004Type\022" - "\017\n\013TYPE_DOUBLE\020\001\022\016\n\nTYPE_FLOAT\020\002\022\016\n\nTYPE" - "_INT64\020\003\022\017\n\013TYPE_UINT64\020\004\022\016\n\nTYPE_INT32\020" - "\005\022\020\n\014TYPE_FIXED64\020\006\022\020\n\014TYPE_FIXED32\020\007\022\r\n" - "\tTYPE_BOOL\020\010\022\017\n\013TYPE_STRING\020\t\022\016\n\nTYPE_GR" - "OUP\020\n\022\020\n\014TYPE_MESSAGE\020\013\022\016\n\nTYPE_BYTES\020\014\022" - "\017\n\013TYPE_UINT32\020\r\022\r\n\tTYPE_ENUM\020\016\022\021\n\rTYPE_" - "SFIXED32\020\017\022\021\n\rTYPE_SFIXED64\020\020\022\017\n\013TYPE_SI" - "NT32\020\021\022\017\n\013TYPE_SINT64\020\022\"C\n\005Label\022\022\n\016LABE" - "L_OPTIONAL\020\001\022\022\n\016LABEL_REQUIRED\020\002\022\022\n\016LABE" - "L_REPEATED\020\003\"T\n\024OneofDescriptorProto\022\014\n\004" - "name\030\001 \001(\t\022.\n\007options\030\002 \001(\0132\035.google.pro" - "tobuf.OneofOptions\"\214\001\n\023EnumDescriptorPro" - "to\022\014\n\004name\030\001 \001(\t\0228\n\005value\030\002 \003(\0132).google" - ".protobuf.EnumValueDescriptorProto\022-\n\007op" - "tions\030\003 \001(\0132\034.google.protobuf.EnumOption" - "s\"l\n\030EnumValueDescriptorProto\022\014\n\004name\030\001 " - "\001(\t\022\016\n\006number\030\002 \001(\005\0222\n\007options\030\003 \001(\0132!.g" - "oogle.protobuf.EnumValueOptions\"\220\001\n\026Serv" - "iceDescriptorProto\022\014\n\004name\030\001 \001(\t\0226\n\006meth" - "od\030\002 \003(\0132&.google.protobuf.MethodDescrip" - "torProto\0220\n\007options\030\003 \001(\0132\037.google.proto" - "buf.ServiceOptions\"\301\001\n\025MethodDescriptorP" - "roto\022\014\n\004name\030\001 \001(\t\022\022\n\ninput_type\030\002 \001(\t\022\023" - "\n\013output_type\030\003 \001(\t\022/\n\007options\030\004 \001(\0132\036.g" - "oogle.protobuf.MethodOptions\022\037\n\020client_s" - "treaming\030\005 \001(\010:\005false\022\037\n\020server_streamin" - "g\030\006 \001(\010:\005false\"\264\005\n\013FileOptions\022\024\n\014java_p" - "ackage\030\001 \001(\t\022\034\n\024java_outer_classname\030\010 \001" - "(\t\022\"\n\023java_multiple_files\030\n \001(\010:\005false\022)" - "\n\035java_generate_equals_and_hash\030\024 \001(\010B\002\030" - "\001\022%\n\026java_string_check_utf8\030\033 \001(\010:\005false" - "\022F\n\014optimize_for\030\t \001(\0162).google.protobuf" - ".FileOptions.OptimizeMode:\005SPEED\022\022\n\ngo_p" - "ackage\030\013 \001(\t\022\"\n\023cc_generic_services\030\020 \001(" - "\010:\005false\022$\n\025java_generic_services\030\021 \001(\010:" - "\005false\022\"\n\023py_generic_services\030\022 \001(\010:\005fal" - "se\022\031\n\ndeprecated\030\027 \001(\010:\005false\022\037\n\020cc_enab" - "le_arenas\030\037 \001(\010:\005false\022\031\n\021objc_class_pre" - "fix\030$ \001(\t\022\030\n\020csharp_namespace\030% \001(\t\022\024\n\014s" - "wift_prefix\030\' \001(\t\022\030\n\020php_class_prefix\030( " - "\001(\t\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.goo" - "gle.protobuf.UninterpretedOption\":\n\014Opti" - "mizeMode\022\t\n\005SPEED\020\001\022\r\n\tCODE_SIZE\020\002\022\020\n\014LI" - "TE_RUNTIME\020\003*\t\010\350\007\020\200\200\200\200\002J\004\010&\020\'\"\362\001\n\016Messag" - "eOptions\022&\n\027message_set_wire_format\030\001 \001(" - "\010:\005false\022.\n\037no_standard_descriptor_acces" - "sor\030\002 \001(\010:\005false\022\031\n\ndeprecated\030\003 \001(\010:\005fa" - "lse\022\021\n\tmap_entry\030\007 \001(\010\022C\n\024uninterpreted_" - "option\030\347\007 \003(\0132$.google.protobuf.Uninterp" - "retedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\010\020\tJ\004\010\t\020\n\"\236\003\n\014F" - "ieldOptions\022:\n\005ctype\030\001 \001(\0162#.google.prot" - "obuf.FieldOptions.CType:\006STRING\022\016\n\006packe" - "d\030\002 \001(\010\022\?\n\006jstype\030\006 \001(\0162$.google.protobu" - "f.FieldOptions.JSType:\tJS_NORMAL\022\023\n\004lazy" - "\030\005 \001(\010:\005false\022\031\n\ndeprecated\030\003 \001(\010:\005false" - "\022\023\n\004weak\030\n \001(\010:\005false\022C\n\024uninterpreted_o" - "ption\030\347\007 \003(\0132$.google.protobuf.Uninterpr" - "etedOption\"/\n\005CType\022\n\n\006STRING\020\000\022\010\n\004CORD\020" - "\001\022\020\n\014STRING_PIECE\020\002\"5\n\006JSType\022\r\n\tJS_NORM" - "AL\020\000\022\r\n\tJS_STRING\020\001\022\r\n\tJS_NUMBER\020\002*\t\010\350\007\020" - "\200\200\200\200\002J\004\010\004\020\005\"^\n\014OneofOptions\022C\n\024uninterpr" - "eted_option\030\347\007 \003(\0132$.google.protobuf.Uni" - "nterpretedOption*\t\010\350\007\020\200\200\200\200\002\"\223\001\n\013EnumOpti" - "ons\022\023\n\013allow_alias\030\002 \001(\010\022\031\n\ndeprecated\030\003" - " \001(\010:\005false\022C\n\024uninterpreted_option\030\347\007 \003" - "(\0132$.google.protobuf.UninterpretedOption" - "*\t\010\350\007\020\200\200\200\200\002J\004\010\005\020\006\"}\n\020EnumValueOptions\022\031\n" - "\ndeprecated\030\001 \001(\010:\005false\022C\n\024uninterprete" + "eserved_name\030\n \003(\t\032e\n\016ExtensionRange\022\r\n\005" + "start\030\001 \001(\005\022\013\n\003end\030\002 \001(\005\0227\n\007options\030\003 \001(" + "\0132&.google.protobuf.ExtensionRangeOption" + "s\032+\n\rReservedRange\022\r\n\005start\030\001 \001(\005\022\013\n\003end" + "\030\002 \001(\005\"g\n\025ExtensionRangeOptions\022C\n\024unint" + "erpreted_option\030\347\007 \003(\0132$.google.protobuf" + ".UninterpretedOption*\t\010\350\007\020\200\200\200\200\002\"\274\005\n\024Fiel" + "dDescriptorProto\022\014\n\004name\030\001 \001(\t\022\016\n\006number" + "\030\003 \001(\005\022:\n\005label\030\004 \001(\0162+.google.protobuf." + "FieldDescriptorProto.Label\0228\n\004type\030\005 \001(\016" + "2*.google.protobuf.FieldDescriptorProto." + "Type\022\021\n\ttype_name\030\006 \001(\t\022\020\n\010extendee\030\002 \001(" + "\t\022\025\n\rdefault_value\030\007 \001(\t\022\023\n\013oneof_index\030" + "\t \001(\005\022\021\n\tjson_name\030\n \001(\t\022.\n\007options\030\010 \001(" + "\0132\035.google.protobuf.FieldOptions\"\266\002\n\004Typ" + "e\022\017\n\013TYPE_DOUBLE\020\001\022\016\n\nTYPE_FLOAT\020\002\022\016\n\nTY" + "PE_INT64\020\003\022\017\n\013TYPE_UINT64\020\004\022\016\n\nTYPE_INT3" + "2\020\005\022\020\n\014TYPE_FIXED64\020\006\022\020\n\014TYPE_FIXED32\020\007\022" + "\r\n\tTYPE_BOOL\020\010\022\017\n\013TYPE_STRING\020\t\022\016\n\nTYPE_" + "GROUP\020\n\022\020\n\014TYPE_MESSAGE\020\013\022\016\n\nTYPE_BYTES\020" + "\014\022\017\n\013TYPE_UINT32\020\r\022\r\n\tTYPE_ENUM\020\016\022\021\n\rTYP" + "E_SFIXED32\020\017\022\021\n\rTYPE_SFIXED64\020\020\022\017\n\013TYPE_" + "SINT32\020\021\022\017\n\013TYPE_SINT64\020\022\"C\n\005Label\022\022\n\016LA" + "BEL_OPTIONAL\020\001\022\022\n\016LABEL_REQUIRED\020\002\022\022\n\016LA" + "BEL_REPEATED\020\003\"T\n\024OneofDescriptorProto\022\014" + "\n\004name\030\001 \001(\t\022.\n\007options\030\002 \001(\0132\035.google.p" + "rotobuf.OneofOptions\"\214\001\n\023EnumDescriptorP" + "roto\022\014\n\004name\030\001 \001(\t\0228\n\005value\030\002 \003(\0132).goog" + "le.protobuf.EnumValueDescriptorProto\022-\n\007" + "options\030\003 \001(\0132\034.google.protobuf.EnumOpti" + "ons\"l\n\030EnumValueDescriptorProto\022\014\n\004name\030" + "\001 \001(\t\022\016\n\006number\030\002 \001(\005\0222\n\007options\030\003 \001(\0132!" + ".google.protobuf.EnumValueOptions\"\220\001\n\026Se" + "rviceDescriptorProto\022\014\n\004name\030\001 \001(\t\0226\n\006me" + "thod\030\002 \003(\0132&.google.protobuf.MethodDescr" + "iptorProto\0220\n\007options\030\003 \001(\0132\037.google.pro" + "tobuf.ServiceOptions\"\301\001\n\025MethodDescripto" + "rProto\022\014\n\004name\030\001 \001(\t\022\022\n\ninput_type\030\002 \001(\t" + "\022\023\n\013output_type\030\003 \001(\t\022/\n\007options\030\004 \001(\0132\036" + ".google.protobuf.MethodOptions\022\037\n\020client" + "_streaming\030\005 \001(\010:\005false\022\037\n\020server_stream" + "ing\030\006 \001(\010:\005false\"\264\005\n\013FileOptions\022\024\n\014java" + "_package\030\001 \001(\t\022\034\n\024java_outer_classname\030\010" + " \001(\t\022\"\n\023java_multiple_files\030\n \001(\010:\005false" + "\022)\n\035java_generate_equals_and_hash\030\024 \001(\010B" + "\002\030\001\022%\n\026java_string_check_utf8\030\033 \001(\010:\005fal" + "se\022F\n\014optimize_for\030\t \001(\0162).google.protob" + "uf.FileOptions.OptimizeMode:\005SPEED\022\022\n\ngo" + "_package\030\013 \001(\t\022\"\n\023cc_generic_services\030\020 " + "\001(\010:\005false\022$\n\025java_generic_services\030\021 \001(" + "\010:\005false\022\"\n\023py_generic_services\030\022 \001(\010:\005f" + "alse\022\031\n\ndeprecated\030\027 \001(\010:\005false\022\037\n\020cc_en" + "able_arenas\030\037 \001(\010:\005false\022\031\n\021objc_class_p" + "refix\030$ \001(\t\022\030\n\020csharp_namespace\030% \001(\t\022\024\n" + "\014swift_prefix\030\' \001(\t\022\030\n\020php_class_prefix\030" + "( \001(\t\022C\n\024uninterpreted_option\030\347\007 \003(\0132$.g" + "oogle.protobuf.UninterpretedOption\":\n\014Op" + "timizeMode\022\t\n\005SPEED\020\001\022\r\n\tCODE_SIZE\020\002\022\020\n\014" + "LITE_RUNTIME\020\003*\t\010\350\007\020\200\200\200\200\002J\004\010&\020\'\"\362\001\n\016Mess" + "ageOptions\022&\n\027message_set_wire_format\030\001 " + "\001(\010:\005false\022.\n\037no_standard_descriptor_acc" + "essor\030\002 \001(\010:\005false\022\031\n\ndeprecated\030\003 \001(\010:\005" + "false\022\021\n\tmap_entry\030\007 \001(\010\022C\n\024uninterprete" "d_option\030\347\007 \003(\0132$.google.protobuf.Uninte" - "rpretedOption*\t\010\350\007\020\200\200\200\200\002\"{\n\016ServiceOptio" - "ns\022\031\n\ndeprecated\030! \001(\010:\005false\022C\n\024uninter" + "rpretedOption*\t\010\350\007\020\200\200\200\200\002J\004\010\010\020\tJ\004\010\t\020\n\"\236\003\n" + "\014FieldOptions\022:\n\005ctype\030\001 \001(\0162#.google.pr" + "otobuf.FieldOptions.CType:\006STRING\022\016\n\006pac" + "ked\030\002 \001(\010\022\?\n\006jstype\030\006 \001(\0162$.google.proto" + "buf.FieldOptions.JSType:\tJS_NORMAL\022\023\n\004la" + "zy\030\005 \001(\010:\005false\022\031\n\ndeprecated\030\003 \001(\010:\005fal" + "se\022\023\n\004weak\030\n \001(\010:\005false\022C\n\024uninterpreted" + "_option\030\347\007 \003(\0132$.google.protobuf.Uninter" + "pretedOption\"/\n\005CType\022\n\n\006STRING\020\000\022\010\n\004COR" + "D\020\001\022\020\n\014STRING_PIECE\020\002\"5\n\006JSType\022\r\n\tJS_NO" + "RMAL\020\000\022\r\n\tJS_STRING\020\001\022\r\n\tJS_NUMBER\020\002*\t\010\350" + "\007\020\200\200\200\200\002J\004\010\004\020\005\"^\n\014OneofOptions\022C\n\024uninter" "preted_option\030\347\007 \003(\0132$.google.protobuf.U" - "ninterpretedOption*\t\010\350\007\020\200\200\200\200\002\"\255\002\n\rMethod" - "Options\022\031\n\ndeprecated\030! \001(\010:\005false\022_\n\021id" - "empotency_level\030\" \001(\0162/.google.protobuf." - "MethodOptions.IdempotencyLevel:\023IDEMPOTE" - "NCY_UNKNOWN\022C\n\024uninterpreted_option\030\347\007 \003" - "(\0132$.google.protobuf.UninterpretedOption" - "\"P\n\020IdempotencyLevel\022\027\n\023IDEMPOTENCY_UNKN" - "OWN\020\000\022\023\n\017NO_SIDE_EFFECTS\020\001\022\016\n\nIDEMPOTENT" - "\020\002*\t\010\350\007\020\200\200\200\200\002\"\236\002\n\023UninterpretedOption\022;\n" - "\004name\030\002 \003(\0132-.google.protobuf.Uninterpre" - "tedOption.NamePart\022\030\n\020identifier_value\030\003" - " \001(\t\022\032\n\022positive_int_value\030\004 \001(\004\022\032\n\022nega" - "tive_int_value\030\005 \001(\003\022\024\n\014double_value\030\006 \001" - "(\001\022\024\n\014string_value\030\007 \001(\014\022\027\n\017aggregate_va" - "lue\030\010 \001(\t\0323\n\010NamePart\022\021\n\tname_part\030\001 \002(\t" - "\022\024\n\014is_extension\030\002 \002(\010\"\325\001\n\016SourceCodeInf" - "o\022:\n\010location\030\001 \003(\0132(.google.protobuf.So" - "urceCodeInfo.Location\032\206\001\n\010Location\022\020\n\004pa" - "th\030\001 \003(\005B\002\020\001\022\020\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020leadin" - "g_comments\030\003 \001(\t\022\031\n\021trailing_comments\030\004 " - "\001(\t\022!\n\031leading_detached_comments\030\006 \003(\t\"\247" - "\001\n\021GeneratedCodeInfo\022A\n\nannotation\030\001 \003(\013" - "2-.google.protobuf.GeneratedCodeInfo.Ann" - "otation\032O\n\nAnnotation\022\020\n\004path\030\001 \003(\005B\002\020\001\022" - "\023\n\013source_file\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n\003e" - "nd\030\004 \001(\005B\214\001\n\023com.google.protobufB\020Descri" - "ptorProtosH\001Z>github.com/golang/protobuf" - "/protoc-gen-go/descriptor;descriptor\242\002\003G" - "PB\252\002\032Google.Protobuf.Reflection" + "ninterpretedOption*\t\010\350\007\020\200\200\200\200\002\"\223\001\n\013EnumOp" + "tions\022\023\n\013allow_alias\030\002 \001(\010\022\031\n\ndeprecated" + "\030\003 \001(\010:\005false\022C\n\024uninterpreted_option\030\347\007" + " \003(\0132$.google.protobuf.UninterpretedOpti" + "on*\t\010\350\007\020\200\200\200\200\002J\004\010\005\020\006\"}\n\020EnumValueOptions\022" + "\031\n\ndeprecated\030\001 \001(\010:\005false\022C\n\024uninterpre" + "ted_option\030\347\007 \003(\0132$.google.protobuf.Unin" + "terpretedOption*\t\010\350\007\020\200\200\200\200\002\"{\n\016ServiceOpt" + "ions\022\031\n\ndeprecated\030! \001(\010:\005false\022C\n\024unint" + "erpreted_option\030\347\007 \003(\0132$.google.protobuf" + ".UninterpretedOption*\t\010\350\007\020\200\200\200\200\002\"\255\002\n\rMeth" + "odOptions\022\031\n\ndeprecated\030! \001(\010:\005false\022_\n\021" + "idempotency_level\030\" \001(\0162/.google.protobu" + "f.MethodOptions.IdempotencyLevel:\023IDEMPO" + "TENCY_UNKNOWN\022C\n\024uninterpreted_option\030\347\007" + " \003(\0132$.google.protobuf.UninterpretedOpti" + "on\"P\n\020IdempotencyLevel\022\027\n\023IDEMPOTENCY_UN" + "KNOWN\020\000\022\023\n\017NO_SIDE_EFFECTS\020\001\022\016\n\nIDEMPOTE" + "NT\020\002*\t\010\350\007\020\200\200\200\200\002\"\236\002\n\023UninterpretedOption\022" + ";\n\004name\030\002 \003(\0132-.google.protobuf.Uninterp" + "retedOption.NamePart\022\030\n\020identifier_value" + "\030\003 \001(\t\022\032\n\022positive_int_value\030\004 \001(\004\022\032\n\022ne" + "gative_int_value\030\005 \001(\003\022\024\n\014double_value\030\006" + " \001(\001\022\024\n\014string_value\030\007 \001(\014\022\027\n\017aggregate_" + "value\030\010 \001(\t\0323\n\010NamePart\022\021\n\tname_part\030\001 \002" + "(\t\022\024\n\014is_extension\030\002 \002(\010\"\325\001\n\016SourceCodeI" + "nfo\022:\n\010location\030\001 \003(\0132(.google.protobuf." + "SourceCodeInfo.Location\032\206\001\n\010Location\022\020\n\004" + "path\030\001 \003(\005B\002\020\001\022\020\n\004span\030\002 \003(\005B\002\020\001\022\030\n\020lead" + "ing_comments\030\003 \001(\t\022\031\n\021trailing_comments\030" + "\004 \001(\t\022!\n\031leading_detached_comments\030\006 \003(\t" + "\"\247\001\n\021GeneratedCodeInfo\022A\n\nannotation\030\001 \003" + "(\0132-.google.protobuf.GeneratedCodeInfo.A" + "nnotation\032O\n\nAnnotation\022\020\n\004path\030\001 \003(\005B\002\020" + "\001\022\023\n\013source_file\030\002 \001(\t\022\r\n\005begin\030\003 \001(\005\022\013\n" + "\003end\030\004 \001(\005B\214\001\n\023com.google.protobufB\020Desc" + "riptorProtosH\001Z>github.com/golang/protob" + "uf/protoc-gen-go/descriptor;descriptor\242\002" + "\003GPB\252\002\032Google.Protobuf.Reflection" }; ::google::protobuf::DescriptorPool::InternalAddGeneratedFile( - descriptor, 5591); + descriptor, 5753); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/descriptor.proto", &protobuf_RegisterTypes); - ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); } void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -1053,6 +1018,10 @@ FileDescriptorSet* FileDescriptorSet::New(::google::protobuf::Arena* arena) cons void FileDescriptorSet::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FileDescriptorSet) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + file_.Clear(); _has_bits_.Clear(); _internal_metadata_.Clear(); @@ -1071,7 +1040,7 @@ bool FileDescriptorSet::MergePartialFromCodedStream( // repeated .google.protobuf.FileDescriptorProto file = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_file())); } else { @@ -1082,13 +1051,11 @@ bool FileDescriptorSet::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -1116,7 +1083,7 @@ void FileDescriptorSet::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.FileDescriptorSet) } @@ -1136,7 +1103,7 @@ void FileDescriptorSet::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.FileDescriptorSet) return target; @@ -1149,7 +1116,7 @@ size_t FileDescriptorSet::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.FileDescriptorProto file = 1; { @@ -1218,10 +1185,11 @@ void FileDescriptorSet::Swap(FileDescriptorSet* other) { InternalSwap(other); } void FileDescriptorSet::InternalSwap(FileDescriptorSet* other) { + using std::swap; file_.InternalSwap(&other->file_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata FileDescriptorSet::GetMetadata() const { @@ -1345,12 +1313,8 @@ void FileDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); package_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); syntax_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != internal_default_instance()) { - delete options_; - } - if (this != internal_default_instance()) { - delete source_code_info_; - } + delete options_; + delete source_code_info_; } void FileDescriptorProto::SetCachedSize(int size) const { @@ -1378,6 +1342,10 @@ FileDescriptorProto* FileDescriptorProto::New(::google::protobuf::Arena* arena) void FileDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FileDescriptorProto) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + dependency_.Clear(); message_type_.Clear(); enum_type_.Clear(); @@ -1385,24 +1353,25 @@ void FileDescriptorProto::Clear() { extension_.Clear(); public_dependency_.Clear(); weak_dependency_.Clear(); - if (_has_bits_[0 / 32] & 31u) { - if (has_name()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 31u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*name_.UnsafeRawStringPointer())->clear(); } - if (has_package()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(!package_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*package_.UnsafeRawStringPointer())->clear(); } - if (has_syntax()) { + if (cached_has_bits & 0x00000004u) { GOOGLE_DCHECK(!syntax_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*syntax_.UnsafeRawStringPointer())->clear(); } - if (has_options()) { + if (cached_has_bits & 0x00000008u) { GOOGLE_DCHECK(options_ != NULL); options_->::google::protobuf::FileOptions::Clear(); } - if (has_source_code_info()) { + if (cached_has_bits & 0x00000010u) { GOOGLE_DCHECK(source_code_info_ != NULL); source_code_info_->::google::protobuf::SourceCodeInfo::Clear(); } @@ -1424,7 +1393,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( // optional string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -1440,7 +1409,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( // optional string package = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_package())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -1456,7 +1425,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( // repeated string dependency = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->add_dependency())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -1473,7 +1442,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.DescriptorProto message_type = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(34u)) { + static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_message_type())); } else { @@ -1485,7 +1454,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.EnumDescriptorProto enum_type = 5; case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(42u)) { + static_cast< ::google::protobuf::uint8>(42u /* 42 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_enum_type())); } else { @@ -1497,7 +1466,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.ServiceDescriptorProto service = 6; case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(50u)) { + static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_service())); } else { @@ -1509,7 +1478,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.FieldDescriptorProto extension = 7; case 7: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(58u)) { + static_cast< ::google::protobuf::uint8>(58u /* 58 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_extension())); } else { @@ -1521,7 +1490,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( // optional .google.protobuf.FileOptions options = 8; case 8: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(66u)) { + static_cast< ::google::protobuf::uint8>(66u /* 66 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_options())); } else { @@ -1533,7 +1502,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( // optional .google.protobuf.SourceCodeInfo source_code_info = 9; case 9: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(74u)) { + static_cast< ::google::protobuf::uint8>(74u /* 74 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_source_code_info())); } else { @@ -1545,12 +1514,13 @@ bool FileDescriptorProto::MergePartialFromCodedStream( // repeated int32 public_dependency = 10; case 10: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(80u)) { + static_cast< ::google::protobuf::uint8>(80u /* 80 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( 1, 80u, input, this->mutable_public_dependency()))); - } else if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(82u)) { + } else if ( + static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(82u /* 82 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitiveNoInline< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, this->mutable_public_dependency()))); @@ -1563,12 +1533,13 @@ bool FileDescriptorProto::MergePartialFromCodedStream( // repeated int32 weak_dependency = 11; case 11: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(88u)) { + static_cast< ::google::protobuf::uint8>(88u /* 88 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( 1, 88u, input, this->mutable_weak_dependency()))); - } else if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(90u)) { + } else if ( + static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(90u /* 90 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitiveNoInline< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, this->mutable_weak_dependency()))); @@ -1581,7 +1552,7 @@ bool FileDescriptorProto::MergePartialFromCodedStream( // optional string syntax = 12; case 12: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(98u)) { + static_cast< ::google::protobuf::uint8>(98u /* 98 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_syntax())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -1596,13 +1567,11 @@ bool FileDescriptorProto::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -1713,7 +1682,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.FileDescriptorProto) } @@ -1820,7 +1789,7 @@ void FileDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.FileDescriptorProto) return target; @@ -1833,7 +1802,7 @@ size_t FileDescriptorProto::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated string dependency = 3; total_size += 1 * @@ -2031,6 +2000,7 @@ void FileDescriptorProto::Swap(FileDescriptorProto* other) { InternalSwap(other); } void FileDescriptorProto::InternalSwap(FileDescriptorProto* other) { + using std::swap; dependency_.InternalSwap(&other->dependency_); message_type_.InternalSwap(&other->message_type_); enum_type_.InternalSwap(&other->enum_type_); @@ -2041,11 +2011,11 @@ void FileDescriptorProto::InternalSwap(FileDescriptorProto* other) { name_.Swap(&other->name_); package_.Swap(&other->package_); syntax_.Swap(&other->syntax_); - std::swap(options_, other->options_); - std::swap(source_code_info_, other->source_code_info_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(options_, other->options_); + swap(source_code_info_, other->source_code_info_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata FileDescriptorProto::GetMetadata() const { @@ -2446,9 +2416,10 @@ void FileDescriptorProto::clear_options() { clear_has_options(); } const ::google::protobuf::FileOptions& FileDescriptorProto::options() const { + const ::google::protobuf::FileOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::FileOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::FileOptions*>( + &::google::protobuf::_FileOptions_default_instance_); } ::google::protobuf::FileOptions* FileDescriptorProto::mutable_options() { set_has_options(); @@ -2491,9 +2462,10 @@ void FileDescriptorProto::clear_source_code_info() { clear_has_source_code_info(); } const ::google::protobuf::SourceCodeInfo& FileDescriptorProto::source_code_info() const { + const ::google::protobuf::SourceCodeInfo* p = source_code_info_; // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.source_code_info) - return source_code_info_ != NULL ? *source_code_info_ - : *::google::protobuf::SourceCodeInfo::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceCodeInfo*>( + &::google::protobuf::_SourceCodeInfo_default_instance_); } ::google::protobuf::SourceCodeInfo* FileDescriptorProto::mutable_source_code_info() { set_has_source_code_info(); @@ -2591,6 +2563,7 @@ void FileDescriptorProto::set_allocated_syntax(::std::string* syntax) { #if !defined(_MSC_VER) || _MSC_VER >= 1900 const int DescriptorProto_ExtensionRange::kStartFieldNumber; const int DescriptorProto_ExtensionRange::kEndFieldNumber; +const int DescriptorProto_ExtensionRange::kOptionsFieldNumber; #endif // !defined(_MSC_VER) || _MSC_VER >= 1900 DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange() @@ -2607,6 +2580,11 @@ DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange(const DescriptorP _has_bits_(from._has_bits_), _cached_size_(0) { _internal_metadata_.MergeFrom(from._internal_metadata_); + if (from.has_options()) { + options_ = new ::google::protobuf::ExtensionRangeOptions(*from.options_); + } else { + options_ = NULL; + } ::memcpy(&start_, &from.start_, reinterpret_cast<char*>(&end_) - reinterpret_cast<char*>(&start_) + sizeof(end_)); @@ -2615,8 +2593,8 @@ DescriptorProto_ExtensionRange::DescriptorProto_ExtensionRange(const DescriptorP void DescriptorProto_ExtensionRange::SharedCtor() { _cached_size_ = 0; - ::memset(&start_, 0, reinterpret_cast<char*>(&end_) - - reinterpret_cast<char*>(&start_) + sizeof(end_)); + ::memset(&options_, 0, reinterpret_cast<char*>(&end_) - + reinterpret_cast<char*>(&options_) + sizeof(end_)); } DescriptorProto_ExtensionRange::~DescriptorProto_ExtensionRange() { @@ -2625,6 +2603,7 @@ DescriptorProto_ExtensionRange::~DescriptorProto_ExtensionRange() { } void DescriptorProto_ExtensionRange::SharedDtor() { + delete options_; } void DescriptorProto_ExtensionRange::SetCachedSize(int size) const { @@ -2652,7 +2631,16 @@ DescriptorProto_ExtensionRange* DescriptorProto_ExtensionRange::New(::google::pr void DescriptorProto_ExtensionRange::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.DescriptorProto.ExtensionRange) - if (_has_bits_[0 / 32] & 3u) { + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + if (has_options()) { + GOOGLE_DCHECK(options_ != NULL); + options_->::google::protobuf::ExtensionRangeOptions::Clear(); + } + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 6u) { ::memset(&start_, 0, reinterpret_cast<char*>(&end_) - reinterpret_cast<char*>(&start_) + sizeof(end_)); } @@ -2673,7 +2661,7 @@ bool DescriptorProto_ExtensionRange::MergePartialFromCodedStream( // optional int32 start = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { set_has_start(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -2687,7 +2675,7 @@ bool DescriptorProto_ExtensionRange::MergePartialFromCodedStream( // optional int32 end = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { set_has_end(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -2698,15 +2686,25 @@ bool DescriptorProto_ExtensionRange::MergePartialFromCodedStream( break; } + // optional .google.protobuf.ExtensionRangeOptions options = 3; + case 3: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + input, mutable_options())); + } else { + goto handle_unusual; + } + break; + } + default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -2728,18 +2726,24 @@ void DescriptorProto_ExtensionRange::SerializeWithCachedSizes( cached_has_bits = _has_bits_[0]; // optional int32 start = 1; - if (cached_has_bits & 0x00000001u) { + if (cached_has_bits & 0x00000002u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->start(), output); } // optional int32 end = 2; - if (cached_has_bits & 0x00000002u) { + if (cached_has_bits & 0x00000004u) { ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->end(), output); } + // optional .google.protobuf.ExtensionRangeOptions options = 3; + if (cached_has_bits & 0x00000001u) { + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 3, *this->options_, output); + } + if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.DescriptorProto.ExtensionRange) } @@ -2752,18 +2756,25 @@ void DescriptorProto_ExtensionRange::SerializeWithCachedSizes( cached_has_bits = _has_bits_[0]; // optional int32 start = 1; - if (cached_has_bits & 0x00000001u) { + if (cached_has_bits & 0x00000002u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->start(), target); } // optional int32 end = 2; - if (cached_has_bits & 0x00000002u) { + if (cached_has_bits & 0x00000004u) { target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->end(), target); } + // optional .google.protobuf.ExtensionRangeOptions options = 3; + if (cached_has_bits & 0x00000001u) { + target = ::google::protobuf::internal::WireFormatLite:: + InternalWriteMessageNoVirtualToArray( + 3, *this->options_, deterministic, target); + } + if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.DescriptorProto.ExtensionRange) return target; @@ -2776,9 +2787,16 @@ size_t DescriptorProto_ExtensionRange::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } - if (_has_bits_[0 / 32] & 3u) { + if (_has_bits_[0 / 32] & 7u) { + // optional .google.protobuf.ExtensionRangeOptions options = 3; + if (has_options()) { + total_size += 1 + + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + *this->options_); + } + // optional int32 start = 1; if (has_start()) { total_size += 1 + @@ -2824,11 +2842,14 @@ void DescriptorProto_ExtensionRange::MergeFrom(const DescriptorProto_ExtensionRa (void) cached_has_bits; cached_has_bits = from._has_bits_[0]; - if (cached_has_bits & 3u) { + if (cached_has_bits & 7u) { if (cached_has_bits & 0x00000001u) { - start_ = from.start_; + mutable_options()->::google::protobuf::ExtensionRangeOptions::MergeFrom(from.options()); } if (cached_has_bits & 0x00000002u) { + start_ = from.start_; + } + if (cached_has_bits & 0x00000004u) { end_ = from.end_; } _has_bits_[0] |= cached_has_bits; @@ -2850,6 +2871,9 @@ void DescriptorProto_ExtensionRange::CopyFrom(const DescriptorProto_ExtensionRan } bool DescriptorProto_ExtensionRange::IsInitialized() const { + if (has_options()) { + if (!this->options_->IsInitialized()) return false; + } return true; } @@ -2858,11 +2882,13 @@ void DescriptorProto_ExtensionRange::Swap(DescriptorProto_ExtensionRange* other) InternalSwap(other); } void DescriptorProto_ExtensionRange::InternalSwap(DescriptorProto_ExtensionRange* other) { - std::swap(start_, other->start_); - std::swap(end_, other->end_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + using std::swap; + swap(options_, other->options_); + swap(start_, other->start_); + swap(end_, other->end_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata DescriptorProto_ExtensionRange::GetMetadata() const { @@ -2875,13 +2901,13 @@ void DescriptorProto_ExtensionRange::InternalSwap(DescriptorProto_ExtensionRange // optional int32 start = 1; bool DescriptorProto_ExtensionRange::has_start() const { - return (_has_bits_[0] & 0x00000001u) != 0; + return (_has_bits_[0] & 0x00000002u) != 0; } void DescriptorProto_ExtensionRange::set_has_start() { - _has_bits_[0] |= 0x00000001u; + _has_bits_[0] |= 0x00000002u; } void DescriptorProto_ExtensionRange::clear_has_start() { - _has_bits_[0] &= ~0x00000001u; + _has_bits_[0] &= ~0x00000002u; } void DescriptorProto_ExtensionRange::clear_start() { start_ = 0; @@ -2899,13 +2925,13 @@ void DescriptorProto_ExtensionRange::set_start(::google::protobuf::int32 value) // optional int32 end = 2; bool DescriptorProto_ExtensionRange::has_end() const { - return (_has_bits_[0] & 0x00000002u) != 0; + return (_has_bits_[0] & 0x00000004u) != 0; } void DescriptorProto_ExtensionRange::set_has_end() { - _has_bits_[0] |= 0x00000002u; + _has_bits_[0] |= 0x00000004u; } void DescriptorProto_ExtensionRange::clear_has_end() { - _has_bits_[0] &= ~0x00000002u; + _has_bits_[0] &= ~0x00000004u; } void DescriptorProto_ExtensionRange::clear_end() { end_ = 0; @@ -2921,6 +2947,52 @@ void DescriptorProto_ExtensionRange::set_end(::google::protobuf::int32 value) { // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ExtensionRange.end) } +// optional .google.protobuf.ExtensionRangeOptions options = 3; +bool DescriptorProto_ExtensionRange::has_options() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +void DescriptorProto_ExtensionRange::set_has_options() { + _has_bits_[0] |= 0x00000001u; +} +void DescriptorProto_ExtensionRange::clear_has_options() { + _has_bits_[0] &= ~0x00000001u; +} +void DescriptorProto_ExtensionRange::clear_options() { + if (options_ != NULL) options_->::google::protobuf::ExtensionRangeOptions::Clear(); + clear_has_options(); +} +const ::google::protobuf::ExtensionRangeOptions& DescriptorProto_ExtensionRange::options() const { + const ::google::protobuf::ExtensionRangeOptions* p = options_; + // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.ExtensionRange.options) + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::ExtensionRangeOptions*>( + &::google::protobuf::_ExtensionRangeOptions_default_instance_); +} +::google::protobuf::ExtensionRangeOptions* DescriptorProto_ExtensionRange::mutable_options() { + set_has_options(); + if (options_ == NULL) { + options_ = new ::google::protobuf::ExtensionRangeOptions; + } + // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.ExtensionRange.options) + return options_; +} +::google::protobuf::ExtensionRangeOptions* DescriptorProto_ExtensionRange::release_options() { + // @@protoc_insertion_point(field_release:google.protobuf.DescriptorProto.ExtensionRange.options) + clear_has_options(); + ::google::protobuf::ExtensionRangeOptions* temp = options_; + options_ = NULL; + return temp; +} +void DescriptorProto_ExtensionRange::set_allocated_options(::google::protobuf::ExtensionRangeOptions* options) { + delete options_; + options_ = options; + if (options) { + set_has_options(); + } else { + clear_has_options(); + } + // @@protoc_insertion_point(field_set_allocated:google.protobuf.DescriptorProto.ExtensionRange.options) +} + #endif // PROTOBUF_INLINE_NOT_IN_HEADERS // =================================================================== @@ -2989,7 +3061,12 @@ DescriptorProto_ReservedRange* DescriptorProto_ReservedRange::New(::google::prot void DescriptorProto_ReservedRange::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.DescriptorProto.ReservedRange) - if (_has_bits_[0 / 32] & 3u) { + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 3u) { ::memset(&start_, 0, reinterpret_cast<char*>(&end_) - reinterpret_cast<char*>(&start_) + sizeof(end_)); } @@ -3010,7 +3087,7 @@ bool DescriptorProto_ReservedRange::MergePartialFromCodedStream( // optional int32 start = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { set_has_start(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -3024,7 +3101,7 @@ bool DescriptorProto_ReservedRange::MergePartialFromCodedStream( // optional int32 end = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { set_has_end(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -3037,13 +3114,11 @@ bool DescriptorProto_ReservedRange::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -3076,7 +3151,7 @@ void DescriptorProto_ReservedRange::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.DescriptorProto.ReservedRange) } @@ -3100,7 +3175,7 @@ void DescriptorProto_ReservedRange::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.DescriptorProto.ReservedRange) return target; @@ -3113,7 +3188,7 @@ size_t DescriptorProto_ReservedRange::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } if (_has_bits_[0 / 32] & 3u) { // optional int32 start = 1; @@ -3195,11 +3270,12 @@ void DescriptorProto_ReservedRange::Swap(DescriptorProto_ReservedRange* other) { InternalSwap(other); } void DescriptorProto_ReservedRange::InternalSwap(DescriptorProto_ReservedRange* other) { - std::swap(start_, other->start_); - std::swap(end_, other->end_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + using std::swap; + swap(start_, other->start_); + swap(end_, other->end_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata DescriptorProto_ReservedRange::GetMetadata() const { @@ -3322,9 +3398,7 @@ DescriptorProto::~DescriptorProto() { void DescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != internal_default_instance()) { - delete options_; - } + delete options_; } void DescriptorProto::SetCachedSize(int size) const { @@ -3352,6 +3426,10 @@ DescriptorProto* DescriptorProto::New(::google::protobuf::Arena* arena) const { void DescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.DescriptorProto) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + field_.Clear(); nested_type_.Clear(); enum_type_.Clear(); @@ -3360,12 +3438,13 @@ void DescriptorProto::Clear() { oneof_decl_.Clear(); reserved_range_.Clear(); reserved_name_.Clear(); - if (_has_bits_[0 / 32] & 3u) { - if (has_name()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*name_.UnsafeRawStringPointer())->clear(); } - if (has_options()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(options_ != NULL); options_->::google::protobuf::MessageOptions::Clear(); } @@ -3387,7 +3466,7 @@ bool DescriptorProto::MergePartialFromCodedStream( // optional string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -3403,7 +3482,7 @@ bool DescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.FieldDescriptorProto field = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_field())); } else { @@ -3415,7 +3494,7 @@ bool DescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.DescriptorProto nested_type = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_nested_type())); } else { @@ -3427,7 +3506,7 @@ bool DescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.EnumDescriptorProto enum_type = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(34u)) { + static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_enum_type())); } else { @@ -3439,7 +3518,7 @@ bool DescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.DescriptorProto.ExtensionRange extension_range = 5; case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(42u)) { + static_cast< ::google::protobuf::uint8>(42u /* 42 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_extension_range())); } else { @@ -3451,7 +3530,7 @@ bool DescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.FieldDescriptorProto extension = 6; case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(50u)) { + static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_extension())); } else { @@ -3463,7 +3542,7 @@ bool DescriptorProto::MergePartialFromCodedStream( // optional .google.protobuf.MessageOptions options = 7; case 7: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(58u)) { + static_cast< ::google::protobuf::uint8>(58u /* 58 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_options())); } else { @@ -3475,7 +3554,7 @@ bool DescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.OneofDescriptorProto oneof_decl = 8; case 8: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(66u)) { + static_cast< ::google::protobuf::uint8>(66u /* 66 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_oneof_decl())); } else { @@ -3487,7 +3566,7 @@ bool DescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.DescriptorProto.ReservedRange reserved_range = 9; case 9: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(74u)) { + static_cast< ::google::protobuf::uint8>(74u /* 74 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_reserved_range())); } else { @@ -3499,7 +3578,7 @@ bool DescriptorProto::MergePartialFromCodedStream( // repeated string reserved_name = 10; case 10: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(82u)) { + static_cast< ::google::protobuf::uint8>(82u /* 82 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->add_reserved_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -3515,13 +3594,11 @@ bool DescriptorProto::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -3612,7 +3689,7 @@ void DescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.DescriptorProto) } @@ -3703,7 +3780,7 @@ void DescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.DescriptorProto) return target; @@ -3716,7 +3793,7 @@ size_t DescriptorProto::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.FieldDescriptorProto field = 2; { @@ -3886,6 +3963,7 @@ bool DescriptorProto::IsInitialized() const { if (!::google::protobuf::internal::AllAreInitialized(this->field())) return false; if (!::google::protobuf::internal::AllAreInitialized(this->nested_type())) return false; if (!::google::protobuf::internal::AllAreInitialized(this->enum_type())) return false; + if (!::google::protobuf::internal::AllAreInitialized(this->extension_range())) return false; if (!::google::protobuf::internal::AllAreInitialized(this->extension())) return false; if (!::google::protobuf::internal::AllAreInitialized(this->oneof_decl())) return false; if (has_options()) { @@ -3899,6 +3977,7 @@ void DescriptorProto::Swap(DescriptorProto* other) { InternalSwap(other); } void DescriptorProto::InternalSwap(DescriptorProto* other) { + using std::swap; field_.InternalSwap(&other->field_); nested_type_.InternalSwap(&other->nested_type_); enum_type_.InternalSwap(&other->enum_type_); @@ -3908,10 +3987,10 @@ void DescriptorProto::InternalSwap(DescriptorProto* other) { reserved_range_.InternalSwap(&other->reserved_range_); reserved_name_.InternalSwap(&other->reserved_name_); name_.Swap(&other->name_); - std::swap(options_, other->options_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(options_, other->options_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata DescriptorProto::GetMetadata() const { @@ -4180,9 +4259,10 @@ void DescriptorProto::clear_options() { clear_has_options(); } const ::google::protobuf::MessageOptions& DescriptorProto::options() const { + const ::google::protobuf::MessageOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::MessageOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::MessageOptions*>( + &::google::protobuf::_MessageOptions_default_instance_); } ::google::protobuf::MessageOptions* DescriptorProto::mutable_options() { set_has_options(); @@ -4314,6 +4394,305 @@ DescriptorProto::mutable_reserved_name() { // =================================================================== #if !defined(_MSC_VER) || _MSC_VER >= 1900 +const int ExtensionRangeOptions::kUninterpretedOptionFieldNumber; +#endif // !defined(_MSC_VER) || _MSC_VER >= 1900 + +ExtensionRangeOptions::ExtensionRangeOptions() + : ::google::protobuf::Message(), _internal_metadata_(NULL) { + if (GOOGLE_PREDICT_TRUE(this != internal_default_instance())) { + protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults(); + } + SharedCtor(); + // @@protoc_insertion_point(constructor:google.protobuf.ExtensionRangeOptions) +} +ExtensionRangeOptions::ExtensionRangeOptions(const ExtensionRangeOptions& from) + : ::google::protobuf::Message(), + _internal_metadata_(NULL), + _has_bits_(from._has_bits_), + _cached_size_(0), + uninterpreted_option_(from.uninterpreted_option_) { + _internal_metadata_.MergeFrom(from._internal_metadata_); + _extensions_.MergeFrom(from._extensions_); + // @@protoc_insertion_point(copy_constructor:google.protobuf.ExtensionRangeOptions) +} + +void ExtensionRangeOptions::SharedCtor() { + _cached_size_ = 0; +} + +ExtensionRangeOptions::~ExtensionRangeOptions() { + // @@protoc_insertion_point(destructor:google.protobuf.ExtensionRangeOptions) + SharedDtor(); +} + +void ExtensionRangeOptions::SharedDtor() { +} + +void ExtensionRangeOptions::SetCachedSize(int size) const { + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); +} +const ::google::protobuf::Descriptor* ExtensionRangeOptions::descriptor() { + protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages].descriptor; +} + +const ExtensionRangeOptions& ExtensionRangeOptions::default_instance() { + protobuf_google_2fprotobuf_2fdescriptor_2eproto::InitDefaults(); + return *internal_default_instance(); +} + +ExtensionRangeOptions* ExtensionRangeOptions::New(::google::protobuf::Arena* arena) const { + ExtensionRangeOptions* n = new ExtensionRangeOptions; + if (arena != NULL) { + arena->Own(n); + } + return n; +} + +void ExtensionRangeOptions::Clear() { +// @@protoc_insertion_point(message_clear_start:google.protobuf.ExtensionRangeOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _extensions_.Clear(); + uninterpreted_option_.Clear(); + _has_bits_.Clear(); + _internal_metadata_.Clear(); +} + +bool ExtensionRangeOptions::MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) { +#define DO_(EXPRESSION) if (!GOOGLE_PREDICT_TRUE(EXPRESSION)) goto failure + ::google::protobuf::uint32 tag; + // @@protoc_insertion_point(parse_start:google.protobuf.ExtensionRangeOptions) + for (;;) { + ::std::pair< ::google::protobuf::uint32, bool> p = input->ReadTagWithCutoffNoLastTag(16383u); + tag = p.first; + if (!p.second) goto handle_unusual; + switch (::google::protobuf::internal::WireFormatLite::GetTagFieldNumber(tag)) { + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + case 999: { + if (static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { + DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( + input, add_uninterpreted_option())); + } else { + goto handle_unusual; + } + break; + } + + default: { + handle_unusual: + if (tag == 0) { + goto success; + } + if ((8000u <= tag)) { + DO_(_extensions_.ParseField(tag, input, + internal_default_instance(), + _internal_metadata_.mutable_unknown_fields())); + continue; + } + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); + break; + } + } + } +success: + // @@protoc_insertion_point(parse_success:google.protobuf.ExtensionRangeOptions) + return true; +failure: + // @@protoc_insertion_point(parse_failure:google.protobuf.ExtensionRangeOptions) + return false; +#undef DO_ +} + +void ExtensionRangeOptions::SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const { + // @@protoc_insertion_point(serialize_start:google.protobuf.ExtensionRangeOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) { + ::google::protobuf::internal::WireFormatLite::WriteMessageMaybeToArray( + 999, this->uninterpreted_option(i), output); + } + + // Extension range [1000, 536870912) + _extensions_.SerializeWithCachedSizes( + 1000, 536870912, output); + + if (_internal_metadata_.have_unknown_fields()) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + _internal_metadata_.unknown_fields(), output); + } + // @@protoc_insertion_point(serialize_end:google.protobuf.ExtensionRangeOptions) +} + +::google::protobuf::uint8* ExtensionRangeOptions::InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const { + // @@protoc_insertion_point(serialize_to_array_start:google.protobuf.ExtensionRangeOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + for (unsigned int i = 0, n = this->uninterpreted_option_size(); i < n; i++) { + target = ::google::protobuf::internal::WireFormatLite:: + InternalWriteMessageNoVirtualToArray( + 999, this->uninterpreted_option(i), deterministic, target); + } + + // Extension range [1000, 536870912) + target = _extensions_.InternalSerializeWithCachedSizesToArray( + 1000, 536870912, deterministic, target); + + if (_internal_metadata_.have_unknown_fields()) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields(), target); + } + // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.ExtensionRangeOptions) + return target; +} + +size_t ExtensionRangeOptions::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:google.protobuf.ExtensionRangeOptions) + size_t total_size = 0; + + total_size += _extensions_.ByteSize(); + + if (_internal_metadata_.have_unknown_fields()) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + _internal_metadata_.unknown_fields()); + } + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + { + unsigned int count = this->uninterpreted_option_size(); + total_size += 2UL * count; + for (unsigned int i = 0; i < count; i++) { + total_size += + ::google::protobuf::internal::WireFormatLite::MessageSizeNoVirtual( + this->uninterpreted_option(i)); + } + } + + int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); + GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); + _cached_size_ = cached_size; + GOOGLE_SAFE_CONCURRENT_WRITES_END(); + return total_size; +} + +void ExtensionRangeOptions::MergeFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:google.protobuf.ExtensionRangeOptions) + GOOGLE_DCHECK_NE(&from, this); + const ExtensionRangeOptions* source = + ::google::protobuf::internal::DynamicCastToGenerated<const ExtensionRangeOptions>( + &from); + if (source == NULL) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:google.protobuf.ExtensionRangeOptions) + ::google::protobuf::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:google.protobuf.ExtensionRangeOptions) + MergeFrom(*source); + } +} + +void ExtensionRangeOptions::MergeFrom(const ExtensionRangeOptions& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:google.protobuf.ExtensionRangeOptions) + GOOGLE_DCHECK_NE(&from, this); + _extensions_.MergeFrom(from._extensions_); + _internal_metadata_.MergeFrom(from._internal_metadata_); + ::google::protobuf::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + uninterpreted_option_.MergeFrom(from.uninterpreted_option_); +} + +void ExtensionRangeOptions::CopyFrom(const ::google::protobuf::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:google.protobuf.ExtensionRangeOptions) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void ExtensionRangeOptions::CopyFrom(const ExtensionRangeOptions& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:google.protobuf.ExtensionRangeOptions) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool ExtensionRangeOptions::IsInitialized() const { + if (!_extensions_.IsInitialized()) { + return false; + } + + if (!::google::protobuf::internal::AllAreInitialized(this->uninterpreted_option())) return false; + return true; +} + +void ExtensionRangeOptions::Swap(ExtensionRangeOptions* other) { + if (other == this) return; + InternalSwap(other); +} +void ExtensionRangeOptions::InternalSwap(ExtensionRangeOptions* other) { + using std::swap; + uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); + swap(_has_bits_[0], other->_has_bits_[0]); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); + _extensions_.Swap(&other->_extensions_); +} + +::google::protobuf::Metadata ExtensionRangeOptions::GetMetadata() const { + protobuf_google_2fprotobuf_2fdescriptor_2eproto::protobuf_AssignDescriptorsOnce(); + return protobuf_google_2fprotobuf_2fdescriptor_2eproto::file_level_metadata[kIndexInFileMessages]; +} + +#if PROTOBUF_INLINE_NOT_IN_HEADERS +// ExtensionRangeOptions + +// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; +int ExtensionRangeOptions::uninterpreted_option_size() const { + return uninterpreted_option_.size(); +} +void ExtensionRangeOptions::clear_uninterpreted_option() { + uninterpreted_option_.Clear(); +} +const ::google::protobuf::UninterpretedOption& ExtensionRangeOptions::uninterpreted_option(int index) const { + // @@protoc_insertion_point(field_get:google.protobuf.ExtensionRangeOptions.uninterpreted_option) + return uninterpreted_option_.Get(index); +} +::google::protobuf::UninterpretedOption* ExtensionRangeOptions::mutable_uninterpreted_option(int index) { + // @@protoc_insertion_point(field_mutable:google.protobuf.ExtensionRangeOptions.uninterpreted_option) + return uninterpreted_option_.Mutable(index); +} +::google::protobuf::UninterpretedOption* ExtensionRangeOptions::add_uninterpreted_option() { + // @@protoc_insertion_point(field_add:google.protobuf.ExtensionRangeOptions.uninterpreted_option) + return uninterpreted_option_.Add(); +} +::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* +ExtensionRangeOptions::mutable_uninterpreted_option() { + // @@protoc_insertion_point(field_mutable_list:google.protobuf.ExtensionRangeOptions.uninterpreted_option) + return &uninterpreted_option_; +} +const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& +ExtensionRangeOptions::uninterpreted_option() const { + // @@protoc_insertion_point(field_list:google.protobuf.ExtensionRangeOptions.uninterpreted_option) + return uninterpreted_option_; +} + +#endif // PROTOBUF_INLINE_NOT_IN_HEADERS + +// =================================================================== + +#if !defined(_MSC_VER) || _MSC_VER >= 1900 const int FieldDescriptorProto::kNameFieldNumber; const int FieldDescriptorProto::kNumberFieldNumber; const int FieldDescriptorProto::kLabelFieldNumber; @@ -4395,9 +4774,7 @@ void FieldDescriptorProto::SharedDtor() { type_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); default_value_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); json_name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != internal_default_instance()) { - delete options_; - } + delete options_; } void FieldDescriptorProto::SetCachedSize(int size) const { @@ -4425,37 +4802,42 @@ FieldDescriptorProto* FieldDescriptorProto::New(::google::protobuf::Arena* arena void FieldDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FieldDescriptorProto) - if (_has_bits_[0 / 32] & 63u) { - if (has_name()) { + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 63u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*name_.UnsafeRawStringPointer())->clear(); } - if (has_extendee()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(!extendee_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*extendee_.UnsafeRawStringPointer())->clear(); } - if (has_type_name()) { + if (cached_has_bits & 0x00000004u) { GOOGLE_DCHECK(!type_name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*type_name_.UnsafeRawStringPointer())->clear(); } - if (has_default_value()) { + if (cached_has_bits & 0x00000008u) { GOOGLE_DCHECK(!default_value_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*default_value_.UnsafeRawStringPointer())->clear(); } - if (has_json_name()) { + if (cached_has_bits & 0x00000010u) { GOOGLE_DCHECK(!json_name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*json_name_.UnsafeRawStringPointer())->clear(); } - if (has_options()) { + if (cached_has_bits & 0x00000020u) { GOOGLE_DCHECK(options_ != NULL); options_->::google::protobuf::FieldOptions::Clear(); } } - if (_has_bits_[0 / 32] & 192u) { + if (cached_has_bits & 192u) { ::memset(&number_, 0, reinterpret_cast<char*>(&oneof_index_) - reinterpret_cast<char*>(&number_) + sizeof(oneof_index_)); } - if (_has_bits_[8 / 32] & 768u) { + if (cached_has_bits & 768u) { label_ = 1; type_ = 1; } @@ -4476,7 +4858,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( // optional string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -4492,7 +4874,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( // optional string extendee = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_extendee())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -4508,7 +4890,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( // optional int32 number = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(24u)) { + static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) { set_has_number(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -4522,7 +4904,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( // optional .google.protobuf.FieldDescriptorProto.Label label = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(32u)) { + static_cast< ::google::protobuf::uint8>(32u /* 32 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -4541,7 +4923,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( // optional .google.protobuf.FieldDescriptorProto.Type type = 5; case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(40u)) { + static_cast< ::google::protobuf::uint8>(40u /* 40 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -4560,7 +4942,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( // optional string type_name = 6; case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(50u)) { + static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_type_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -4576,7 +4958,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( // optional string default_value = 7; case 7: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(58u)) { + static_cast< ::google::protobuf::uint8>(58u /* 58 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_default_value())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -4592,7 +4974,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( // optional .google.protobuf.FieldOptions options = 8; case 8: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(66u)) { + static_cast< ::google::protobuf::uint8>(66u /* 66 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_options())); } else { @@ -4604,7 +4986,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( // optional int32 oneof_index = 9; case 9: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(72u)) { + static_cast< ::google::protobuf::uint8>(72u /* 72 & 0xFF */)) { set_has_oneof_index(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -4618,7 +5000,7 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( // optional string json_name = 10; case 10: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(82u)) { + static_cast< ::google::protobuf::uint8>(82u /* 82 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_json_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -4633,13 +5015,11 @@ bool FieldDescriptorProto::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -4740,7 +5120,7 @@ void FieldDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.FieldDescriptorProto) } @@ -4838,7 +5218,7 @@ void FieldDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.FieldDescriptorProto) return target; @@ -4851,7 +5231,7 @@ size_t FieldDescriptorProto::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } if (_has_bits_[0 / 32] & 255u) { // optional string name = 1; @@ -5024,19 +5404,20 @@ void FieldDescriptorProto::Swap(FieldDescriptorProto* other) { InternalSwap(other); } void FieldDescriptorProto::InternalSwap(FieldDescriptorProto* other) { + using std::swap; name_.Swap(&other->name_); extendee_.Swap(&other->extendee_); type_name_.Swap(&other->type_name_); default_value_.Swap(&other->default_value_); json_name_.Swap(&other->json_name_); - std::swap(options_, other->options_); - std::swap(number_, other->number_); - std::swap(oneof_index_, other->oneof_index_); - std::swap(label_, other->label_); - std::swap(type_, other->type_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(options_, other->options_); + swap(number_, other->number_); + swap(oneof_index_, other->oneof_index_); + swap(label_, other->label_); + swap(type_, other->type_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata FieldDescriptorProto::GetMetadata() const { @@ -5475,9 +5856,10 @@ void FieldDescriptorProto::clear_options() { clear_has_options(); } const ::google::protobuf::FieldOptions& FieldDescriptorProto::options() const { + const ::google::protobuf::FieldOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::FieldOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::FieldOptions*>( + &::google::protobuf::_FieldOptions_default_instance_); } ::google::protobuf::FieldOptions* FieldDescriptorProto::mutable_options() { set_has_options(); @@ -5553,9 +5935,7 @@ OneofDescriptorProto::~OneofDescriptorProto() { void OneofDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != internal_default_instance()) { - delete options_; - } + delete options_; } void OneofDescriptorProto::SetCachedSize(int size) const { @@ -5583,12 +5963,17 @@ OneofDescriptorProto* OneofDescriptorProto::New(::google::protobuf::Arena* arena void OneofDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.OneofDescriptorProto) - if (_has_bits_[0 / 32] & 3u) { - if (has_name()) { + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*name_.UnsafeRawStringPointer())->clear(); } - if (has_options()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(options_ != NULL); options_->::google::protobuf::OneofOptions::Clear(); } @@ -5610,7 +5995,7 @@ bool OneofDescriptorProto::MergePartialFromCodedStream( // optional string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -5626,7 +6011,7 @@ bool OneofDescriptorProto::MergePartialFromCodedStream( // optional .google.protobuf.OneofOptions options = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_options())); } else { @@ -5637,13 +6022,11 @@ bool OneofDescriptorProto::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -5682,7 +6065,7 @@ void OneofDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.OneofDescriptorProto) } @@ -5714,7 +6097,7 @@ void OneofDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.OneofDescriptorProto) return target; @@ -5727,7 +6110,7 @@ size_t OneofDescriptorProto::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } if (_has_bits_[0 / 32] & 3u) { // optional string name = 1; @@ -5812,11 +6195,12 @@ void OneofDescriptorProto::Swap(OneofDescriptorProto* other) { InternalSwap(other); } void OneofDescriptorProto::InternalSwap(OneofDescriptorProto* other) { + using std::swap; name_.Swap(&other->name_); - std::swap(options_, other->options_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(options_, other->options_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata OneofDescriptorProto::GetMetadata() const { @@ -5905,9 +6289,10 @@ void OneofDescriptorProto::clear_options() { clear_has_options(); } const ::google::protobuf::OneofOptions& OneofDescriptorProto::options() const { + const ::google::protobuf::OneofOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.OneofDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::OneofOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::OneofOptions*>( + &::google::protobuf::_OneofOptions_default_instance_); } ::google::protobuf::OneofOptions* OneofDescriptorProto::mutable_options() { set_has_options(); @@ -5985,9 +6370,7 @@ EnumDescriptorProto::~EnumDescriptorProto() { void EnumDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != internal_default_instance()) { - delete options_; - } + delete options_; } void EnumDescriptorProto::SetCachedSize(int size) const { @@ -6015,13 +6398,18 @@ EnumDescriptorProto* EnumDescriptorProto::New(::google::protobuf::Arena* arena) void EnumDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumDescriptorProto) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + value_.Clear(); - if (_has_bits_[0 / 32] & 3u) { - if (has_name()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*name_.UnsafeRawStringPointer())->clear(); } - if (has_options()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(options_ != NULL); options_->::google::protobuf::EnumOptions::Clear(); } @@ -6043,7 +6431,7 @@ bool EnumDescriptorProto::MergePartialFromCodedStream( // optional string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -6059,7 +6447,7 @@ bool EnumDescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.EnumValueDescriptorProto value = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_value())); } else { @@ -6071,7 +6459,7 @@ bool EnumDescriptorProto::MergePartialFromCodedStream( // optional .google.protobuf.EnumOptions options = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_options())); } else { @@ -6082,13 +6470,11 @@ bool EnumDescriptorProto::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -6133,7 +6519,7 @@ void EnumDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.EnumDescriptorProto) } @@ -6172,7 +6558,7 @@ void EnumDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.EnumDescriptorProto) return target; @@ -6185,7 +6571,7 @@ size_t EnumDescriptorProto::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.EnumValueDescriptorProto value = 2; { @@ -6283,12 +6669,13 @@ void EnumDescriptorProto::Swap(EnumDescriptorProto* other) { InternalSwap(other); } void EnumDescriptorProto::InternalSwap(EnumDescriptorProto* other) { + using std::swap; value_.InternalSwap(&other->value_); name_.Swap(&other->name_); - std::swap(options_, other->options_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(options_, other->options_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata EnumDescriptorProto::GetMetadata() const { @@ -6407,9 +6794,10 @@ void EnumDescriptorProto::clear_options() { clear_has_options(); } const ::google::protobuf::EnumOptions& EnumDescriptorProto::options() const { + const ::google::protobuf::EnumOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.EnumDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::EnumOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::EnumOptions*>( + &::google::protobuf::_EnumOptions_default_instance_); } ::google::protobuf::EnumOptions* EnumDescriptorProto::mutable_options() { set_has_options(); @@ -6488,9 +6876,7 @@ EnumValueDescriptorProto::~EnumValueDescriptorProto() { void EnumValueDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != internal_default_instance()) { - delete options_; - } + delete options_; } void EnumValueDescriptorProto::SetCachedSize(int size) const { @@ -6518,12 +6904,17 @@ EnumValueDescriptorProto* EnumValueDescriptorProto::New(::google::protobuf::Aren void EnumValueDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumValueDescriptorProto) - if (_has_bits_[0 / 32] & 3u) { - if (has_name()) { + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*name_.UnsafeRawStringPointer())->clear(); } - if (has_options()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(options_ != NULL); options_->::google::protobuf::EnumValueOptions::Clear(); } @@ -6546,7 +6937,7 @@ bool EnumValueDescriptorProto::MergePartialFromCodedStream( // optional string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -6562,7 +6953,7 @@ bool EnumValueDescriptorProto::MergePartialFromCodedStream( // optional int32 number = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { set_has_number(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -6576,7 +6967,7 @@ bool EnumValueDescriptorProto::MergePartialFromCodedStream( // optional .google.protobuf.EnumValueOptions options = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_options())); } else { @@ -6587,13 +6978,11 @@ bool EnumValueDescriptorProto::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -6637,7 +7026,7 @@ void EnumValueDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.EnumValueDescriptorProto) } @@ -6674,7 +7063,7 @@ void EnumValueDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.EnumValueDescriptorProto) return target; @@ -6687,7 +7076,7 @@ size_t EnumValueDescriptorProto::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } if (_has_bits_[0 / 32] & 7u) { // optional string name = 1; @@ -6783,12 +7172,13 @@ void EnumValueDescriptorProto::Swap(EnumValueDescriptorProto* other) { InternalSwap(other); } void EnumValueDescriptorProto::InternalSwap(EnumValueDescriptorProto* other) { + using std::swap; name_.Swap(&other->name_); - std::swap(options_, other->options_); - std::swap(number_, other->number_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(options_, other->options_); + swap(number_, other->number_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata EnumValueDescriptorProto::GetMetadata() const { @@ -6901,9 +7291,10 @@ void EnumValueDescriptorProto::clear_options() { clear_has_options(); } const ::google::protobuf::EnumValueOptions& EnumValueDescriptorProto::options() const { + const ::google::protobuf::EnumValueOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.EnumValueDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::EnumValueOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::EnumValueOptions*>( + &::google::protobuf::_EnumValueOptions_default_instance_); } ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::mutable_options() { set_has_options(); @@ -6981,9 +7372,7 @@ ServiceDescriptorProto::~ServiceDescriptorProto() { void ServiceDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != internal_default_instance()) { - delete options_; - } + delete options_; } void ServiceDescriptorProto::SetCachedSize(int size) const { @@ -7011,13 +7400,18 @@ ServiceDescriptorProto* ServiceDescriptorProto::New(::google::protobuf::Arena* a void ServiceDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.ServiceDescriptorProto) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + method_.Clear(); - if (_has_bits_[0 / 32] & 3u) { - if (has_name()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*name_.UnsafeRawStringPointer())->clear(); } - if (has_options()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(options_ != NULL); options_->::google::protobuf::ServiceOptions::Clear(); } @@ -7039,7 +7433,7 @@ bool ServiceDescriptorProto::MergePartialFromCodedStream( // optional string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -7055,7 +7449,7 @@ bool ServiceDescriptorProto::MergePartialFromCodedStream( // repeated .google.protobuf.MethodDescriptorProto method = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_method())); } else { @@ -7067,7 +7461,7 @@ bool ServiceDescriptorProto::MergePartialFromCodedStream( // optional .google.protobuf.ServiceOptions options = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_options())); } else { @@ -7078,13 +7472,11 @@ bool ServiceDescriptorProto::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -7129,7 +7521,7 @@ void ServiceDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.ServiceDescriptorProto) } @@ -7168,7 +7560,7 @@ void ServiceDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.ServiceDescriptorProto) return target; @@ -7181,7 +7573,7 @@ size_t ServiceDescriptorProto::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.MethodDescriptorProto method = 2; { @@ -7279,12 +7671,13 @@ void ServiceDescriptorProto::Swap(ServiceDescriptorProto* other) { InternalSwap(other); } void ServiceDescriptorProto::InternalSwap(ServiceDescriptorProto* other) { + using std::swap; method_.InternalSwap(&other->method_); name_.Swap(&other->name_); - std::swap(options_, other->options_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(options_, other->options_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata ServiceDescriptorProto::GetMetadata() const { @@ -7403,9 +7796,10 @@ void ServiceDescriptorProto::clear_options() { clear_has_options(); } const ::google::protobuf::ServiceOptions& ServiceDescriptorProto::options() const { + const ::google::protobuf::ServiceOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.ServiceDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::ServiceOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::ServiceOptions*>( + &::google::protobuf::_ServiceOptions_default_instance_); } ::google::protobuf::ServiceOptions* ServiceDescriptorProto::mutable_options() { set_has_options(); @@ -7501,9 +7895,7 @@ void MethodDescriptorProto::SharedDtor() { name_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); input_type_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); output_type_.DestroyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); - if (this != internal_default_instance()) { - delete options_; - } + delete options_; } void MethodDescriptorProto::SetCachedSize(int size) const { @@ -7531,25 +7923,30 @@ MethodDescriptorProto* MethodDescriptorProto::New(::google::protobuf::Arena* are void MethodDescriptorProto::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.MethodDescriptorProto) - if (_has_bits_[0 / 32] & 15u) { - if (has_name()) { + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 15u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!name_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*name_.UnsafeRawStringPointer())->clear(); } - if (has_input_type()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(!input_type_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*input_type_.UnsafeRawStringPointer())->clear(); } - if (has_output_type()) { + if (cached_has_bits & 0x00000004u) { GOOGLE_DCHECK(!output_type_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*output_type_.UnsafeRawStringPointer())->clear(); } - if (has_options()) { + if (cached_has_bits & 0x00000008u) { GOOGLE_DCHECK(options_ != NULL); options_->::google::protobuf::MethodOptions::Clear(); } } - if (_has_bits_[0 / 32] & 48u) { + if (cached_has_bits & 48u) { ::memset(&client_streaming_, 0, reinterpret_cast<char*>(&server_streaming_) - reinterpret_cast<char*>(&client_streaming_) + sizeof(server_streaming_)); } @@ -7570,7 +7967,7 @@ bool MethodDescriptorProto::MergePartialFromCodedStream( // optional string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -7586,7 +7983,7 @@ bool MethodDescriptorProto::MergePartialFromCodedStream( // optional string input_type = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_input_type())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -7602,7 +7999,7 @@ bool MethodDescriptorProto::MergePartialFromCodedStream( // optional string output_type = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_output_type())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -7618,7 +8015,7 @@ bool MethodDescriptorProto::MergePartialFromCodedStream( // optional .google.protobuf.MethodOptions options = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(34u)) { + static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_options())); } else { @@ -7630,7 +8027,7 @@ bool MethodDescriptorProto::MergePartialFromCodedStream( // optional bool client_streaming = 5 [default = false]; case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(40u)) { + static_cast< ::google::protobuf::uint8>(40u /* 40 & 0xFF */)) { set_has_client_streaming(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -7644,7 +8041,7 @@ bool MethodDescriptorProto::MergePartialFromCodedStream( // optional bool server_streaming = 6 [default = false]; case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(48u)) { + static_cast< ::google::protobuf::uint8>(48u /* 48 & 0xFF */)) { set_has_server_streaming(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -7657,13 +8054,11 @@ bool MethodDescriptorProto::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -7732,7 +8127,7 @@ void MethodDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.MethodDescriptorProto) } @@ -7796,7 +8191,7 @@ void MethodDescriptorProto::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.MethodDescriptorProto) return target; @@ -7809,7 +8204,7 @@ size_t MethodDescriptorProto::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } if (_has_bits_[0 / 32] & 63u) { // optional string name = 1; @@ -7933,15 +8328,16 @@ void MethodDescriptorProto::Swap(MethodDescriptorProto* other) { InternalSwap(other); } void MethodDescriptorProto::InternalSwap(MethodDescriptorProto* other) { + using std::swap; name_.Swap(&other->name_); input_type_.Swap(&other->input_type_); output_type_.Swap(&other->output_type_); - std::swap(options_, other->options_); - std::swap(client_streaming_, other->client_streaming_); - std::swap(server_streaming_, other->server_streaming_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(options_, other->options_); + swap(client_streaming_, other->client_streaming_); + swap(server_streaming_, other->server_streaming_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata MethodDescriptorProto::GetMetadata() const { @@ -8156,9 +8552,10 @@ void MethodDescriptorProto::clear_options() { clear_has_options(); } const ::google::protobuf::MethodOptions& MethodDescriptorProto::options() const { + const ::google::protobuf::MethodOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::MethodOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::MethodOptions*>( + &::google::protobuf::_MethodOptions_default_instance_); } ::google::protobuf::MethodOptions* MethodDescriptorProto::mutable_options() { set_has_options(); @@ -8362,40 +8759,45 @@ FileOptions* FileOptions::New(::google::protobuf::Arena* arena) const { void FileOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FileOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + _extensions_.Clear(); uninterpreted_option_.Clear(); - if (_has_bits_[0 / 32] & 127u) { - if (has_java_package()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 127u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!java_package_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*java_package_.UnsafeRawStringPointer())->clear(); } - if (has_java_outer_classname()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(!java_outer_classname_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*java_outer_classname_.UnsafeRawStringPointer())->clear(); } - if (has_go_package()) { + if (cached_has_bits & 0x00000004u) { GOOGLE_DCHECK(!go_package_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*go_package_.UnsafeRawStringPointer())->clear(); } - if (has_objc_class_prefix()) { + if (cached_has_bits & 0x00000008u) { GOOGLE_DCHECK(!objc_class_prefix_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*objc_class_prefix_.UnsafeRawStringPointer())->clear(); } - if (has_csharp_namespace()) { + if (cached_has_bits & 0x00000010u) { GOOGLE_DCHECK(!csharp_namespace_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*csharp_namespace_.UnsafeRawStringPointer())->clear(); } - if (has_swift_prefix()) { + if (cached_has_bits & 0x00000020u) { GOOGLE_DCHECK(!swift_prefix_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*swift_prefix_.UnsafeRawStringPointer())->clear(); } - if (has_php_class_prefix()) { + if (cached_has_bits & 0x00000040u) { GOOGLE_DCHECK(!php_class_prefix_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*php_class_prefix_.UnsafeRawStringPointer())->clear(); } } java_multiple_files_ = false; - if (_has_bits_[8 / 32] & 65280u) { + if (cached_has_bits & 65280u) { ::memset(&java_generate_equals_and_hash_, 0, reinterpret_cast<char*>(&cc_enable_arenas_) - reinterpret_cast<char*>(&java_generate_equals_and_hash_) + sizeof(cc_enable_arenas_)); optimize_for_ = 1; @@ -8417,7 +8819,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional string java_package = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_java_package())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -8433,7 +8835,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional string java_outer_classname = 8; case 8: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(66u)) { + static_cast< ::google::protobuf::uint8>(66u /* 66 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_java_outer_classname())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -8449,7 +8851,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional .google.protobuf.FileOptions.OptimizeMode optimize_for = 9 [default = SPEED]; case 9: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(72u)) { + static_cast< ::google::protobuf::uint8>(72u /* 72 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -8468,7 +8870,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional bool java_multiple_files = 10 [default = false]; case 10: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(80u)) { + static_cast< ::google::protobuf::uint8>(80u /* 80 & 0xFF */)) { set_has_java_multiple_files(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -8482,7 +8884,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional string go_package = 11; case 11: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(90u)) { + static_cast< ::google::protobuf::uint8>(90u /* 90 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_go_package())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -8498,7 +8900,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional bool cc_generic_services = 16 [default = false]; case 16: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(128u)) { + static_cast< ::google::protobuf::uint8>(128u /* 128 & 0xFF */)) { set_has_cc_generic_services(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -8512,7 +8914,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional bool java_generic_services = 17 [default = false]; case 17: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(136u)) { + static_cast< ::google::protobuf::uint8>(136u /* 136 & 0xFF */)) { set_has_java_generic_services(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -8526,7 +8928,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional bool py_generic_services = 18 [default = false]; case 18: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(144u)) { + static_cast< ::google::protobuf::uint8>(144u /* 144 & 0xFF */)) { set_has_py_generic_services(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -8540,7 +8942,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional bool java_generate_equals_and_hash = 20 [deprecated = true]; case 20: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(160u)) { + static_cast< ::google::protobuf::uint8>(160u /* 160 & 0xFF */)) { set_has_java_generate_equals_and_hash(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -8554,7 +8956,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional bool deprecated = 23 [default = false]; case 23: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(184u)) { + static_cast< ::google::protobuf::uint8>(184u /* 184 & 0xFF */)) { set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -8568,7 +8970,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional bool java_string_check_utf8 = 27 [default = false]; case 27: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(216u)) { + static_cast< ::google::protobuf::uint8>(216u /* 216 & 0xFF */)) { set_has_java_string_check_utf8(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -8582,7 +8984,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional bool cc_enable_arenas = 31 [default = false]; case 31: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(248u)) { + static_cast< ::google::protobuf::uint8>(248u /* 248 & 0xFF */)) { set_has_cc_enable_arenas(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -8596,7 +8998,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional string objc_class_prefix = 36; case 36: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(290u)) { + static_cast< ::google::protobuf::uint8>(34u /* 290 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_objc_class_prefix())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -8612,7 +9014,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional string csharp_namespace = 37; case 37: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(298u)) { + static_cast< ::google::protobuf::uint8>(42u /* 298 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_csharp_namespace())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -8628,7 +9030,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional string swift_prefix = 39; case 39: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(314u)) { + static_cast< ::google::protobuf::uint8>(58u /* 314 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_swift_prefix())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -8644,7 +9046,7 @@ bool FileOptions::MergePartialFromCodedStream( // optional string php_class_prefix = 40; case 40: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(322u)) { + static_cast< ::google::protobuf::uint8>(66u /* 322 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_php_class_prefix())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -8660,7 +9062,7 @@ bool FileOptions::MergePartialFromCodedStream( // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(7994u)) { + static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { @@ -8671,18 +9073,17 @@ bool FileOptions::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, internal_default_instance(), - mutable_unknown_fields())); + DO_(_extensions_.ParseField(tag, input, + internal_default_instance(), + _internal_metadata_.mutable_unknown_fields())); continue; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -8831,7 +9232,7 @@ void FileOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.FileOptions) } @@ -8979,7 +9380,7 @@ void FileOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.FileOptions) return target; @@ -8994,7 +9395,7 @@ size_t FileOptions::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; { @@ -9229,6 +9630,7 @@ void FileOptions::Swap(FileOptions* other) { InternalSwap(other); } void FileOptions::InternalSwap(FileOptions* other) { + using std::swap; uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); java_package_.Swap(&other->java_package_); java_outer_classname_.Swap(&other->java_outer_classname_); @@ -9237,18 +9639,18 @@ void FileOptions::InternalSwap(FileOptions* other) { csharp_namespace_.Swap(&other->csharp_namespace_); swift_prefix_.Swap(&other->swift_prefix_); php_class_prefix_.Swap(&other->php_class_prefix_); - std::swap(java_multiple_files_, other->java_multiple_files_); - std::swap(java_generate_equals_and_hash_, other->java_generate_equals_and_hash_); - std::swap(java_string_check_utf8_, other->java_string_check_utf8_); - std::swap(cc_generic_services_, other->cc_generic_services_); - std::swap(java_generic_services_, other->java_generic_services_); - std::swap(py_generic_services_, other->py_generic_services_); - std::swap(deprecated_, other->deprecated_); - std::swap(cc_enable_arenas_, other->cc_enable_arenas_); - std::swap(optimize_for_, other->optimize_for_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(java_multiple_files_, other->java_multiple_files_); + swap(java_generate_equals_and_hash_, other->java_generate_equals_and_hash_); + swap(java_string_check_utf8_, other->java_string_check_utf8_); + swap(cc_generic_services_, other->cc_generic_services_); + swap(java_generic_services_, other->java_generic_services_); + swap(py_generic_services_, other->py_generic_services_); + swap(deprecated_, other->deprecated_); + swap(cc_enable_arenas_, other->cc_enable_arenas_); + swap(optimize_for_, other->optimize_for_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); _extensions_.Swap(&other->_extensions_); } @@ -10021,9 +10423,14 @@ MessageOptions* MessageOptions::New(::google::protobuf::Arena* arena) const { void MessageOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.MessageOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + _extensions_.Clear(); uninterpreted_option_.Clear(); - if (_has_bits_[0 / 32] & 15u) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 15u) { ::memset(&message_set_wire_format_, 0, reinterpret_cast<char*>(&map_entry_) - reinterpret_cast<char*>(&message_set_wire_format_) + sizeof(map_entry_)); } @@ -10044,7 +10451,7 @@ bool MessageOptions::MergePartialFromCodedStream( // optional bool message_set_wire_format = 1 [default = false]; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { set_has_message_set_wire_format(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -10058,7 +10465,7 @@ bool MessageOptions::MergePartialFromCodedStream( // optional bool no_standard_descriptor_accessor = 2 [default = false]; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { set_has_no_standard_descriptor_accessor(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -10072,7 +10479,7 @@ bool MessageOptions::MergePartialFromCodedStream( // optional bool deprecated = 3 [default = false]; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(24u)) { + static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) { set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -10086,7 +10493,7 @@ bool MessageOptions::MergePartialFromCodedStream( // optional bool map_entry = 7; case 7: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(56u)) { + static_cast< ::google::protobuf::uint8>(56u /* 56 & 0xFF */)) { set_has_map_entry(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -10100,7 +10507,7 @@ bool MessageOptions::MergePartialFromCodedStream( // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(7994u)) { + static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { @@ -10111,18 +10518,17 @@ bool MessageOptions::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, internal_default_instance(), - mutable_unknown_fields())); + DO_(_extensions_.ParseField(tag, input, + internal_default_instance(), + _internal_metadata_.mutable_unknown_fields())); continue; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -10175,7 +10581,7 @@ void MessageOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.MessageOptions) } @@ -10220,7 +10626,7 @@ void MessageOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.MessageOptions) return target; @@ -10235,7 +10641,7 @@ size_t MessageOptions::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; { @@ -10347,14 +10753,15 @@ void MessageOptions::Swap(MessageOptions* other) { InternalSwap(other); } void MessageOptions::InternalSwap(MessageOptions* other) { + using std::swap; uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); - std::swap(message_set_wire_format_, other->message_set_wire_format_); - std::swap(no_standard_descriptor_accessor_, other->no_standard_descriptor_accessor_); - std::swap(deprecated_, other->deprecated_); - std::swap(map_entry_, other->map_entry_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(message_set_wire_format_, other->message_set_wire_format_); + swap(no_standard_descriptor_accessor_, other->no_standard_descriptor_accessor_); + swap(deprecated_, other->deprecated_); + swap(map_entry_, other->map_entry_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); _extensions_.Swap(&other->_extensions_); } @@ -10567,9 +10974,14 @@ FieldOptions* FieldOptions::New(::google::protobuf::Arena* arena) const { void FieldOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FieldOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + _extensions_.Clear(); uninterpreted_option_.Clear(); - if (_has_bits_[0 / 32] & 63u) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 63u) { ::memset(&ctype_, 0, reinterpret_cast<char*>(&jstype_) - reinterpret_cast<char*>(&ctype_) + sizeof(jstype_)); } @@ -10590,7 +11002,7 @@ bool FieldOptions::MergePartialFromCodedStream( // optional .google.protobuf.FieldOptions.CType ctype = 1 [default = STRING]; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -10609,7 +11021,7 @@ bool FieldOptions::MergePartialFromCodedStream( // optional bool packed = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { set_has_packed(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -10623,7 +11035,7 @@ bool FieldOptions::MergePartialFromCodedStream( // optional bool deprecated = 3 [default = false]; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(24u)) { + static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) { set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -10637,7 +11049,7 @@ bool FieldOptions::MergePartialFromCodedStream( // optional bool lazy = 5 [default = false]; case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(40u)) { + static_cast< ::google::protobuf::uint8>(40u /* 40 & 0xFF */)) { set_has_lazy(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -10651,7 +11063,7 @@ bool FieldOptions::MergePartialFromCodedStream( // optional .google.protobuf.FieldOptions.JSType jstype = 6 [default = JS_NORMAL]; case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(48u)) { + static_cast< ::google::protobuf::uint8>(48u /* 48 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -10670,7 +11082,7 @@ bool FieldOptions::MergePartialFromCodedStream( // optional bool weak = 10 [default = false]; case 10: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(80u)) { + static_cast< ::google::protobuf::uint8>(80u /* 80 & 0xFF */)) { set_has_weak(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -10684,7 +11096,7 @@ bool FieldOptions::MergePartialFromCodedStream( // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(7994u)) { + static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { @@ -10695,18 +11107,17 @@ bool FieldOptions::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, internal_default_instance(), - mutable_unknown_fields())); + DO_(_extensions_.ParseField(tag, input, + internal_default_instance(), + _internal_metadata_.mutable_unknown_fields())); continue; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -10771,7 +11182,7 @@ void FieldOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.FieldOptions) } @@ -10828,7 +11239,7 @@ void FieldOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.FieldOptions) return target; @@ -10843,7 +11254,7 @@ size_t FieldOptions::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; { @@ -10973,16 +11384,17 @@ void FieldOptions::Swap(FieldOptions* other) { InternalSwap(other); } void FieldOptions::InternalSwap(FieldOptions* other) { + using std::swap; uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); - std::swap(ctype_, other->ctype_); - std::swap(packed_, other->packed_); - std::swap(lazy_, other->lazy_); - std::swap(deprecated_, other->deprecated_); - std::swap(weak_, other->weak_); - std::swap(jstype_, other->jstype_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(ctype_, other->ctype_); + swap(packed_, other->packed_); + swap(lazy_, other->lazy_); + swap(deprecated_, other->deprecated_); + swap(weak_, other->weak_); + swap(jstype_, other->jstype_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); _extensions_.Swap(&other->_extensions_); } @@ -11234,6 +11646,10 @@ OneofOptions* OneofOptions::New(::google::protobuf::Arena* arena) const { void OneofOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.OneofOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + _extensions_.Clear(); uninterpreted_option_.Clear(); _has_bits_.Clear(); @@ -11253,7 +11669,7 @@ bool OneofOptions::MergePartialFromCodedStream( // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(7994u)) { + static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { @@ -11264,18 +11680,17 @@ bool OneofOptions::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, internal_default_instance(), - mutable_unknown_fields())); + DO_(_extensions_.ParseField(tag, input, + internal_default_instance(), + _internal_metadata_.mutable_unknown_fields())); continue; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -11307,7 +11722,7 @@ void OneofOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.OneofOptions) } @@ -11331,7 +11746,7 @@ void OneofOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.OneofOptions) return target; @@ -11346,7 +11761,7 @@ size_t OneofOptions::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; { @@ -11420,10 +11835,11 @@ void OneofOptions::Swap(OneofOptions* other) { InternalSwap(other); } void OneofOptions::InternalSwap(OneofOptions* other) { + using std::swap; uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); _extensions_.Swap(&other->_extensions_); } @@ -11536,9 +11952,14 @@ EnumOptions* EnumOptions::New(::google::protobuf::Arena* arena) const { void EnumOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + _extensions_.Clear(); uninterpreted_option_.Clear(); - if (_has_bits_[0 / 32] & 3u) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 3u) { ::memset(&allow_alias_, 0, reinterpret_cast<char*>(&deprecated_) - reinterpret_cast<char*>(&allow_alias_) + sizeof(deprecated_)); } @@ -11559,7 +11980,7 @@ bool EnumOptions::MergePartialFromCodedStream( // optional bool allow_alias = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { set_has_allow_alias(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -11573,7 +11994,7 @@ bool EnumOptions::MergePartialFromCodedStream( // optional bool deprecated = 3 [default = false]; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(24u)) { + static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) { set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -11587,7 +12008,7 @@ bool EnumOptions::MergePartialFromCodedStream( // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(7994u)) { + static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { @@ -11598,18 +12019,17 @@ bool EnumOptions::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, internal_default_instance(), - mutable_unknown_fields())); + DO_(_extensions_.ParseField(tag, input, + internal_default_instance(), + _internal_metadata_.mutable_unknown_fields())); continue; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -11652,7 +12072,7 @@ void EnumOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.EnumOptions) } @@ -11687,7 +12107,7 @@ void EnumOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.EnumOptions) return target; @@ -11702,7 +12122,7 @@ size_t EnumOptions::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; { @@ -11798,12 +12218,13 @@ void EnumOptions::Swap(EnumOptions* other) { InternalSwap(other); } void EnumOptions::InternalSwap(EnumOptions* other) { + using std::swap; uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); - std::swap(allow_alias_, other->allow_alias_); - std::swap(deprecated_, other->deprecated_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(allow_alias_, other->allow_alias_); + swap(deprecated_, other->deprecated_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); _extensions_.Swap(&other->_extensions_); } @@ -11960,6 +12381,10 @@ EnumValueOptions* EnumValueOptions::New(::google::protobuf::Arena* arena) const void EnumValueOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumValueOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + _extensions_.Clear(); uninterpreted_option_.Clear(); deprecated_ = false; @@ -11980,7 +12405,7 @@ bool EnumValueOptions::MergePartialFromCodedStream( // optional bool deprecated = 1 [default = false]; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -11994,7 +12419,7 @@ bool EnumValueOptions::MergePartialFromCodedStream( // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(7994u)) { + static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { @@ -12005,18 +12430,17 @@ bool EnumValueOptions::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, internal_default_instance(), - mutable_unknown_fields())); + DO_(_extensions_.ParseField(tag, input, + internal_default_instance(), + _internal_metadata_.mutable_unknown_fields())); continue; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -12054,7 +12478,7 @@ void EnumValueOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.EnumValueOptions) } @@ -12084,7 +12508,7 @@ void EnumValueOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.EnumValueOptions) return target; @@ -12099,7 +12523,7 @@ size_t EnumValueOptions::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; { @@ -12181,11 +12605,12 @@ void EnumValueOptions::Swap(EnumValueOptions* other) { InternalSwap(other); } void EnumValueOptions::InternalSwap(EnumValueOptions* other) { + using std::swap; uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); - std::swap(deprecated_, other->deprecated_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(deprecated_, other->deprecated_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); _extensions_.Swap(&other->_extensions_); } @@ -12318,6 +12743,10 @@ ServiceOptions* ServiceOptions::New(::google::protobuf::Arena* arena) const { void ServiceOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.ServiceOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + _extensions_.Clear(); uninterpreted_option_.Clear(); deprecated_ = false; @@ -12338,7 +12767,7 @@ bool ServiceOptions::MergePartialFromCodedStream( // optional bool deprecated = 33 [default = false]; case 33: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(264u)) { + static_cast< ::google::protobuf::uint8>(8u /* 264 & 0xFF */)) { set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -12352,7 +12781,7 @@ bool ServiceOptions::MergePartialFromCodedStream( // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(7994u)) { + static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { @@ -12363,18 +12792,17 @@ bool ServiceOptions::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, internal_default_instance(), - mutable_unknown_fields())); + DO_(_extensions_.ParseField(tag, input, + internal_default_instance(), + _internal_metadata_.mutable_unknown_fields())); continue; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -12412,7 +12840,7 @@ void ServiceOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.ServiceOptions) } @@ -12442,7 +12870,7 @@ void ServiceOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.ServiceOptions) return target; @@ -12457,7 +12885,7 @@ size_t ServiceOptions::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; { @@ -12539,11 +12967,12 @@ void ServiceOptions::Swap(ServiceOptions* other) { InternalSwap(other); } void ServiceOptions::InternalSwap(ServiceOptions* other) { + using std::swap; uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); - std::swap(deprecated_, other->deprecated_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(deprecated_, other->deprecated_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); _extensions_.Swap(&other->_extensions_); } @@ -12680,9 +13109,14 @@ MethodOptions* MethodOptions::New(::google::protobuf::Arena* arena) const { void MethodOptions::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.MethodOptions) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + _extensions_.Clear(); uninterpreted_option_.Clear(); - if (_has_bits_[0 / 32] & 3u) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 3u) { ::memset(&deprecated_, 0, reinterpret_cast<char*>(&idempotency_level_) - reinterpret_cast<char*>(&deprecated_) + sizeof(idempotency_level_)); } @@ -12703,7 +13137,7 @@ bool MethodOptions::MergePartialFromCodedStream( // optional bool deprecated = 33 [default = false]; case 33: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(264u)) { + static_cast< ::google::protobuf::uint8>(8u /* 264 & 0xFF */)) { set_has_deprecated(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -12717,7 +13151,7 @@ bool MethodOptions::MergePartialFromCodedStream( // optional .google.protobuf.MethodOptions.IdempotencyLevel idempotency_level = 34 [default = IDEMPOTENCY_UNKNOWN]; case 34: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(272u)) { + static_cast< ::google::protobuf::uint8>(16u /* 272 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -12736,7 +13170,7 @@ bool MethodOptions::MergePartialFromCodedStream( // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; case 999: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(7994u)) { + static_cast< ::google::protobuf::uint8>(58u /* 7994 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_uninterpreted_option())); } else { @@ -12747,18 +13181,17 @@ bool MethodOptions::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } if ((8000u <= tag)) { - DO_(_extensions_.ParseField(tag, input, internal_default_instance(), - mutable_unknown_fields())); + DO_(_extensions_.ParseField(tag, input, + internal_default_instance(), + _internal_metadata_.mutable_unknown_fields())); continue; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -12802,7 +13235,7 @@ void MethodOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.MethodOptions) } @@ -12838,7 +13271,7 @@ void MethodOptions::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.MethodOptions) return target; @@ -12853,7 +13286,7 @@ size_t MethodOptions::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; { @@ -12950,12 +13383,13 @@ void MethodOptions::Swap(MethodOptions* other) { InternalSwap(other); } void MethodOptions::InternalSwap(MethodOptions* other) { + using std::swap; uninterpreted_option_.InternalSwap(&other->uninterpreted_option_); - std::swap(deprecated_, other->deprecated_); - std::swap(idempotency_level_, other->idempotency_level_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(deprecated_, other->deprecated_); + swap(idempotency_level_, other->idempotency_level_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); _extensions_.Swap(&other->_extensions_); } @@ -13117,6 +13551,10 @@ UninterpretedOption_NamePart* UninterpretedOption_NamePart::New(::google::protob void UninterpretedOption_NamePart::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.UninterpretedOption.NamePart) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + if (has_name_part()) { GOOGLE_DCHECK(!name_part_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*name_part_.UnsafeRawStringPointer())->clear(); @@ -13139,7 +13577,7 @@ bool UninterpretedOption_NamePart::MergePartialFromCodedStream( // required string name_part = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name_part())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -13155,7 +13593,7 @@ bool UninterpretedOption_NamePart::MergePartialFromCodedStream( // required bool is_extension = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { set_has_is_extension(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -13168,13 +13606,11 @@ bool UninterpretedOption_NamePart::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -13212,7 +13648,7 @@ void UninterpretedOption_NamePart::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.UninterpretedOption.NamePart) } @@ -13242,7 +13678,7 @@ void UninterpretedOption_NamePart::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.UninterpretedOption.NamePart) return target; @@ -13273,7 +13709,7 @@ size_t UninterpretedOption_NamePart::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } if (((_has_bits_[0] & 0x00000003) ^ 0x00000003) == 0) { // All required fields are present. // required string name_part = 1; @@ -13353,11 +13789,12 @@ void UninterpretedOption_NamePart::Swap(UninterpretedOption_NamePart* other) { InternalSwap(other); } void UninterpretedOption_NamePart::InternalSwap(UninterpretedOption_NamePart* other) { + using std::swap; name_part_.Swap(&other->name_part_); - std::swap(is_extension_, other->is_extension_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(is_extension_, other->is_extension_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata UninterpretedOption_NamePart::GetMetadata() const { @@ -13547,22 +13984,27 @@ UninterpretedOption* UninterpretedOption::New(::google::protobuf::Arena* arena) void UninterpretedOption::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.UninterpretedOption) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + name_.Clear(); - if (_has_bits_[0 / 32] & 7u) { - if (has_identifier_value()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 7u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!identifier_value_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*identifier_value_.UnsafeRawStringPointer())->clear(); } - if (has_string_value()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(!string_value_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*string_value_.UnsafeRawStringPointer())->clear(); } - if (has_aggregate_value()) { + if (cached_has_bits & 0x00000004u) { GOOGLE_DCHECK(!aggregate_value_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*aggregate_value_.UnsafeRawStringPointer())->clear(); } } - if (_has_bits_[0 / 32] & 56u) { + if (cached_has_bits & 56u) { ::memset(&positive_int_value_, 0, reinterpret_cast<char*>(&double_value_) - reinterpret_cast<char*>(&positive_int_value_) + sizeof(double_value_)); } @@ -13583,7 +14025,7 @@ bool UninterpretedOption::MergePartialFromCodedStream( // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_name())); } else { @@ -13595,7 +14037,7 @@ bool UninterpretedOption::MergePartialFromCodedStream( // optional string identifier_value = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_identifier_value())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -13611,7 +14053,7 @@ bool UninterpretedOption::MergePartialFromCodedStream( // optional uint64 positive_int_value = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(32u)) { + static_cast< ::google::protobuf::uint8>(32u /* 32 & 0xFF */)) { set_has_positive_int_value(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>( @@ -13625,7 +14067,7 @@ bool UninterpretedOption::MergePartialFromCodedStream( // optional int64 negative_int_value = 5; case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(40u)) { + static_cast< ::google::protobuf::uint8>(40u /* 40 & 0xFF */)) { set_has_negative_int_value(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>( @@ -13639,7 +14081,7 @@ bool UninterpretedOption::MergePartialFromCodedStream( // optional double double_value = 6; case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(49u)) { + static_cast< ::google::protobuf::uint8>(49u /* 49 & 0xFF */)) { set_has_double_value(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< double, ::google::protobuf::internal::WireFormatLite::TYPE_DOUBLE>( @@ -13653,7 +14095,7 @@ bool UninterpretedOption::MergePartialFromCodedStream( // optional bytes string_value = 7; case 7: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(58u)) { + static_cast< ::google::protobuf::uint8>(58u /* 58 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadBytes( input, this->mutable_string_value())); } else { @@ -13665,7 +14107,7 @@ bool UninterpretedOption::MergePartialFromCodedStream( // optional string aggregate_value = 8; case 8: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(66u)) { + static_cast< ::google::protobuf::uint8>(66u /* 66 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_aggregate_value())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -13680,13 +14122,11 @@ bool UninterpretedOption::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -13756,7 +14196,7 @@ void UninterpretedOption::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.UninterpretedOption) } @@ -13821,7 +14261,7 @@ void UninterpretedOption::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.UninterpretedOption) return target; @@ -13834,7 +14274,7 @@ size_t UninterpretedOption::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.UninterpretedOption.NamePart name = 2; { @@ -13970,16 +14410,17 @@ void UninterpretedOption::Swap(UninterpretedOption* other) { InternalSwap(other); } void UninterpretedOption::InternalSwap(UninterpretedOption* other) { + using std::swap; name_.InternalSwap(&other->name_); identifier_value_.Swap(&other->identifier_value_); string_value_.Swap(&other->string_value_); aggregate_value_.Swap(&other->aggregate_value_); - std::swap(positive_int_value_, other->positive_int_value_); - std::swap(negative_int_value_, other->negative_int_value_); - std::swap(double_value_, other->double_value_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(positive_int_value_, other->positive_int_value_); + swap(negative_int_value_, other->negative_int_value_); + swap(double_value_, other->double_value_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata UninterpretedOption::GetMetadata() const { @@ -14362,15 +14803,20 @@ SourceCodeInfo_Location* SourceCodeInfo_Location::New(::google::protobuf::Arena* void SourceCodeInfo_Location::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.SourceCodeInfo.Location) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + path_.Clear(); span_.Clear(); leading_detached_comments_.Clear(); - if (_has_bits_[0 / 32] & 3u) { - if (has_leading_comments()) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 3u) { + if (cached_has_bits & 0x00000001u) { GOOGLE_DCHECK(!leading_comments_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*leading_comments_.UnsafeRawStringPointer())->clear(); } - if (has_trailing_comments()) { + if (cached_has_bits & 0x00000002u) { GOOGLE_DCHECK(!trailing_comments_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*trailing_comments_.UnsafeRawStringPointer())->clear(); } @@ -14392,12 +14838,13 @@ bool SourceCodeInfo_Location::MergePartialFromCodedStream( // repeated int32 path = 1 [packed = true]; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, this->mutable_path()))); - } else if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + } else if ( + static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( 1, 10u, input, this->mutable_path()))); @@ -14410,12 +14857,13 @@ bool SourceCodeInfo_Location::MergePartialFromCodedStream( // repeated int32 span = 2 [packed = true]; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, this->mutable_span()))); - } else if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + } else if ( + static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( 1, 18u, input, this->mutable_span()))); @@ -14428,7 +14876,7 @@ bool SourceCodeInfo_Location::MergePartialFromCodedStream( // optional string leading_comments = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_leading_comments())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -14444,7 +14892,7 @@ bool SourceCodeInfo_Location::MergePartialFromCodedStream( // optional string trailing_comments = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(34u)) { + static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_trailing_comments())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -14460,7 +14908,7 @@ bool SourceCodeInfo_Location::MergePartialFromCodedStream( // repeated string leading_detached_comments = 6; case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(50u)) { + static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->add_leading_detached_comments())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -14476,13 +14924,11 @@ bool SourceCodeInfo_Location::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -14555,7 +15001,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.SourceCodeInfo.Location) } @@ -14625,7 +15071,7 @@ void SourceCodeInfo_Location::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.SourceCodeInfo.Location) return target; @@ -14638,7 +15084,7 @@ size_t SourceCodeInfo_Location::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated int32 path = 1 [packed = true]; { @@ -14762,14 +15208,15 @@ void SourceCodeInfo_Location::Swap(SourceCodeInfo_Location* other) { InternalSwap(other); } void SourceCodeInfo_Location::InternalSwap(SourceCodeInfo_Location* other) { + using std::swap; path_.InternalSwap(&other->path_); span_.InternalSwap(&other->span_); leading_detached_comments_.InternalSwap(&other->leading_detached_comments_); leading_comments_.Swap(&other->leading_comments_); trailing_comments_.Swap(&other->trailing_comments_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata SourceCodeInfo_Location::GetMetadata() const { @@ -15098,6 +15545,10 @@ SourceCodeInfo* SourceCodeInfo::New(::google::protobuf::Arena* arena) const { void SourceCodeInfo::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.SourceCodeInfo) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + location_.Clear(); _has_bits_.Clear(); _internal_metadata_.Clear(); @@ -15116,7 +15567,7 @@ bool SourceCodeInfo::MergePartialFromCodedStream( // repeated .google.protobuf.SourceCodeInfo.Location location = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_location())); } else { @@ -15127,13 +15578,11 @@ bool SourceCodeInfo::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -15161,7 +15610,7 @@ void SourceCodeInfo::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.SourceCodeInfo) } @@ -15181,7 +15630,7 @@ void SourceCodeInfo::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.SourceCodeInfo) return target; @@ -15194,7 +15643,7 @@ size_t SourceCodeInfo::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.SourceCodeInfo.Location location = 1; { @@ -15262,10 +15711,11 @@ void SourceCodeInfo::Swap(SourceCodeInfo* other) { InternalSwap(other); } void SourceCodeInfo::InternalSwap(SourceCodeInfo* other) { + using std::swap; location_.InternalSwap(&other->location_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata SourceCodeInfo::GetMetadata() const { @@ -15383,12 +15833,17 @@ GeneratedCodeInfo_Annotation* GeneratedCodeInfo_Annotation::New(::google::protob void GeneratedCodeInfo_Annotation::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.GeneratedCodeInfo.Annotation) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + path_.Clear(); if (has_source_file()) { GOOGLE_DCHECK(!source_file_.IsDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited())); (*source_file_.UnsafeRawStringPointer())->clear(); } - if (_has_bits_[0 / 32] & 6u) { + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 6u) { ::memset(&begin_, 0, reinterpret_cast<char*>(&end_) - reinterpret_cast<char*>(&begin_) + sizeof(end_)); } @@ -15409,12 +15864,13 @@ bool GeneratedCodeInfo_Annotation::MergePartialFromCodedStream( // repeated int32 path = 1 [packed = true]; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPackedPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( input, this->mutable_path()))); - } else if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + } else if ( + static_cast< ::google::protobuf::uint8>(tag) == + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadRepeatedPrimitiveNoInline< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( 1, 10u, input, this->mutable_path()))); @@ -15427,7 +15883,7 @@ bool GeneratedCodeInfo_Annotation::MergePartialFromCodedStream( // optional string source_file = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_source_file())); ::google::protobuf::internal::WireFormat::VerifyUTF8StringNamedField( @@ -15443,7 +15899,7 @@ bool GeneratedCodeInfo_Annotation::MergePartialFromCodedStream( // optional int32 begin = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(24u)) { + static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) { set_has_begin(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -15457,7 +15913,7 @@ bool GeneratedCodeInfo_Annotation::MergePartialFromCodedStream( // optional int32 end = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(32u)) { + static_cast< ::google::protobuf::uint8>(32u /* 32 & 0xFF */)) { set_has_end(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -15470,13 +15926,11 @@ bool GeneratedCodeInfo_Annotation::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -15529,7 +15983,7 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.GeneratedCodeInfo.Annotation) } @@ -15576,7 +16030,7 @@ void GeneratedCodeInfo_Annotation::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.GeneratedCodeInfo.Annotation) return target; @@ -15589,7 +16043,7 @@ size_t GeneratedCodeInfo_Annotation::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated int32 path = 1 [packed = true]; { @@ -15698,13 +16152,14 @@ void GeneratedCodeInfo_Annotation::Swap(GeneratedCodeInfo_Annotation* other) { InternalSwap(other); } void GeneratedCodeInfo_Annotation::InternalSwap(GeneratedCodeInfo_Annotation* other) { + using std::swap; path_.InternalSwap(&other->path_); source_file_.Swap(&other->source_file_); - std::swap(begin_, other->begin_); - std::swap(end_, other->end_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(begin_, other->begin_); + swap(end_, other->end_); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata GeneratedCodeInfo_Annotation::GetMetadata() const { @@ -15919,6 +16374,10 @@ GeneratedCodeInfo* GeneratedCodeInfo::New(::google::protobuf::Arena* arena) cons void GeneratedCodeInfo::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.GeneratedCodeInfo) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + annotation_.Clear(); _has_bits_.Clear(); _internal_metadata_.Clear(); @@ -15937,7 +16396,7 @@ bool GeneratedCodeInfo::MergePartialFromCodedStream( // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_annotation())); } else { @@ -15948,13 +16407,11 @@ bool GeneratedCodeInfo::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } DO_(::google::protobuf::internal::WireFormat::SkipField( - input, tag, mutable_unknown_fields())); + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -15982,7 +16439,7 @@ void GeneratedCodeInfo::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { ::google::protobuf::internal::WireFormat::SerializeUnknownFields( - unknown_fields(), output); + _internal_metadata_.unknown_fields(), output); } // @@protoc_insertion_point(serialize_end:google.protobuf.GeneratedCodeInfo) } @@ -16002,7 +16459,7 @@ void GeneratedCodeInfo::SerializeWithCachedSizes( if (_internal_metadata_.have_unknown_fields()) { target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( - unknown_fields(), target); + _internal_metadata_.unknown_fields(), target); } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.GeneratedCodeInfo) return target; @@ -16015,7 +16472,7 @@ size_t GeneratedCodeInfo::ByteSizeLong() const { if (_internal_metadata_.have_unknown_fields()) { total_size += ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( - unknown_fields()); + _internal_metadata_.unknown_fields()); } // repeated .google.protobuf.GeneratedCodeInfo.Annotation annotation = 1; { @@ -16083,10 +16540,11 @@ void GeneratedCodeInfo::Swap(GeneratedCodeInfo* other) { InternalSwap(other); } void GeneratedCodeInfo::InternalSwap(GeneratedCodeInfo* other) { + using std::swap; annotation_.InternalSwap(&other->annotation_); - std::swap(_has_bits_[0], other->_has_bits_[0]); + swap(_has_bits_[0], other->_has_bits_[0]); _internal_metadata_.Swap(&other->_internal_metadata_); - std::swap(_cached_size_, other->_cached_size_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata GeneratedCodeInfo::GetMetadata() const { diff --git a/src/google/protobuf/descriptor.pb.h b/src/google/protobuf/descriptor.pb.h index d1ed2b1f..9c11ccfc 100644 --- a/src/google/protobuf/descriptor.pb.h +++ b/src/google/protobuf/descriptor.pb.h @@ -54,6 +54,9 @@ LIBPROTOBUF_EXPORT extern EnumValueDescriptorProtoDefaultTypeInternal _EnumValue class EnumValueOptions; class EnumValueOptionsDefaultTypeInternal; LIBPROTOBUF_EXPORT extern EnumValueOptionsDefaultTypeInternal _EnumValueOptions_default_instance_; +class ExtensionRangeOptions; +class ExtensionRangeOptionsDefaultTypeInternal; +LIBPROTOBUF_EXPORT extern ExtensionRangeOptionsDefaultTypeInternal _ExtensionRangeOptions_default_instance_; class FieldDescriptorProto; class FieldDescriptorProtoDefaultTypeInternal; LIBPROTOBUF_EXPORT extern FieldDescriptorProtoDefaultTypeInternal _FieldDescriptorProto_default_instance_; @@ -121,8 +124,9 @@ struct LIBPROTOBUF_EXPORT TableStruct { static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; static void InitDefaultsImpl(); - static void Shutdown(); }; void LIBPROTOBUF_EXPORT AddDescriptors(); void LIBPROTOBUF_EXPORT InitDefaults(); @@ -276,11 +280,24 @@ class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message CopyFrom(from); return *this; } + #if LANG_CXX11 + FileDescriptorSet(FileDescriptorSet&& from) noexcept + : FileDescriptorSet() { + *this = ::std::move(from); + } + inline FileDescriptorSet& operator=(FileDescriptorSet&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -296,6 +313,9 @@ class LIBPROTOBUF_EXPORT FileDescriptorSet : public ::google::protobuf::Message 0; void Swap(FileDescriptorSet* other); + friend void swap(FileDescriptorSet& a, FileDescriptorSet& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -371,11 +391,24 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag CopyFrom(from); return *this; } + #if LANG_CXX11 + FileDescriptorProto(FileDescriptorProto&& from) noexcept + : FileDescriptorProto() { + *this = ::std::move(from); + } + inline FileDescriptorProto& operator=(FileDescriptorProto&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -391,6 +424,9 @@ class LIBPROTOBUF_EXPORT FileDescriptorProto : public ::google::protobuf::Messag 1; void Swap(FileDescriptorProto* other); + friend void swap(FileDescriptorProto& a, FileDescriptorProto& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -632,11 +668,24 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto CopyFrom(from); return *this; } + #if LANG_CXX11 + DescriptorProto_ExtensionRange(DescriptorProto_ExtensionRange&& from) noexcept + : DescriptorProto_ExtensionRange() { + *this = ::std::move(from); + } + inline DescriptorProto_ExtensionRange& operator=(DescriptorProto_ExtensionRange&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -652,6 +701,9 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto 2; void Swap(DescriptorProto_ExtensionRange* other); + friend void swap(DescriptorProto_ExtensionRange& a, DescriptorProto_ExtensionRange& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -693,6 +745,15 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto // accessors ------------------------------------------------------- + // optional .google.protobuf.ExtensionRangeOptions options = 3; + bool has_options() const; + void clear_options(); + static const int kOptionsFieldNumber = 3; + const ::google::protobuf::ExtensionRangeOptions& options() const; + ::google::protobuf::ExtensionRangeOptions* mutable_options(); + ::google::protobuf::ExtensionRangeOptions* release_options(); + void set_allocated_options(::google::protobuf::ExtensionRangeOptions* options); + // optional int32 start = 1; bool has_start() const; void clear_start(); @@ -713,10 +774,13 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ExtensionRange : public ::google::proto void clear_has_start(); void set_has_end(); void clear_has_end(); + void set_has_options(); + void clear_has_options(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; ::google::protobuf::internal::HasBits<1> _has_bits_; mutable int _cached_size_; + ::google::protobuf::ExtensionRangeOptions* options_; ::google::protobuf::int32 start_; ::google::protobuf::int32 end_; friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct; @@ -734,11 +798,24 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protob CopyFrom(from); return *this; } + #if LANG_CXX11 + DescriptorProto_ReservedRange(DescriptorProto_ReservedRange&& from) noexcept + : DescriptorProto_ReservedRange() { + *this = ::std::move(from); + } + inline DescriptorProto_ReservedRange& operator=(DescriptorProto_ReservedRange&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -754,6 +831,9 @@ class LIBPROTOBUF_EXPORT DescriptorProto_ReservedRange : public ::google::protob 3; void Swap(DescriptorProto_ReservedRange* other); + friend void swap(DescriptorProto_ReservedRange& a, DescriptorProto_ReservedRange& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -836,11 +916,24 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* CopyFrom(from); return *this; } + #if LANG_CXX11 + DescriptorProto(DescriptorProto&& from) noexcept + : DescriptorProto() { + *this = ::std::move(from); + } + inline DescriptorProto& operator=(DescriptorProto&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -856,6 +949,9 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* 4; void Swap(DescriptorProto* other); + friend void swap(DescriptorProto& a, DescriptorProto& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -1054,6 +1150,120 @@ class LIBPROTOBUF_EXPORT DescriptorProto : public ::google::protobuf::Message /* }; // ------------------------------------------------------------------- +class LIBPROTOBUF_EXPORT ExtensionRangeOptions : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.ExtensionRangeOptions) */ { + public: + ExtensionRangeOptions(); + virtual ~ExtensionRangeOptions(); + + ExtensionRangeOptions(const ExtensionRangeOptions& from); + + inline ExtensionRangeOptions& operator=(const ExtensionRangeOptions& from) { + CopyFrom(from); + return *this; + } + #if LANG_CXX11 + ExtensionRangeOptions(ExtensionRangeOptions&& from) noexcept + : ExtensionRangeOptions() { + *this = ::std::move(from); + } + + inline ExtensionRangeOptions& operator=(ExtensionRangeOptions&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif + inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields(); + } + inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields(); + } + + static const ::google::protobuf::Descriptor* descriptor(); + static const ExtensionRangeOptions& default_instance(); + + static inline const ExtensionRangeOptions* internal_default_instance() { + return reinterpret_cast<const ExtensionRangeOptions*>( + &_ExtensionRangeOptions_default_instance_); + } + static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = + 5; + + void Swap(ExtensionRangeOptions* other); + friend void swap(ExtensionRangeOptions& a, ExtensionRangeOptions& b) { + a.Swap(&b); + } + + // implements Message ---------------------------------------------- + + inline ExtensionRangeOptions* New() const PROTOBUF_FINAL { return New(NULL); } + + ExtensionRangeOptions* New(::google::protobuf::Arena* arena) const PROTOBUF_FINAL; + void CopyFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void MergeFrom(const ::google::protobuf::Message& from) PROTOBUF_FINAL; + void CopyFrom(const ExtensionRangeOptions& from); + void MergeFrom(const ExtensionRangeOptions& from); + void Clear() PROTOBUF_FINAL; + bool IsInitialized() const PROTOBUF_FINAL; + + size_t ByteSizeLong() const PROTOBUF_FINAL; + bool MergePartialFromCodedStream( + ::google::protobuf::io::CodedInputStream* input) PROTOBUF_FINAL; + void SerializeWithCachedSizes( + ::google::protobuf::io::CodedOutputStream* output) const PROTOBUF_FINAL; + ::google::protobuf::uint8* InternalSerializeWithCachedSizesToArray( + bool deterministic, ::google::protobuf::uint8* target) const PROTOBUF_FINAL; + int GetCachedSize() const PROTOBUF_FINAL { return _cached_size_; } + private: + void SharedCtor(); + void SharedDtor(); + void SetCachedSize(int size) const PROTOBUF_FINAL; + void InternalSwap(ExtensionRangeOptions* other); + private: + inline ::google::protobuf::Arena* GetArenaNoVirtual() const { + return NULL; + } + inline void* MaybeArenaPtr() const { + return NULL; + } + public: + + ::google::protobuf::Metadata GetMetadata() const PROTOBUF_FINAL; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + // repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; + int uninterpreted_option_size() const; + void clear_uninterpreted_option(); + static const int kUninterpretedOptionFieldNumber = 999; + const ::google::protobuf::UninterpretedOption& uninterpreted_option(int index) const; + ::google::protobuf::UninterpretedOption* mutable_uninterpreted_option(int index); + ::google::protobuf::UninterpretedOption* add_uninterpreted_option(); + ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* + mutable_uninterpreted_option(); + const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& + uninterpreted_option() const; + + GOOGLE_PROTOBUF_EXTENSION_ACCESSORS(ExtensionRangeOptions) + // @@protoc_insertion_point(class_scope:google.protobuf.ExtensionRangeOptions) + private: + + ::google::protobuf::internal::ExtensionSet _extensions_; + + ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; + ::google::protobuf::internal::HasBits<1> _has_bits_; + mutable int _cached_size_; + ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption > uninterpreted_option_; + friend struct protobuf_google_2fprotobuf_2fdescriptor_2eproto::TableStruct; +}; +// ------------------------------------------------------------------- + class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:google.protobuf.FieldDescriptorProto) */ { public: FieldDescriptorProto(); @@ -1065,11 +1275,24 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa CopyFrom(from); return *this; } + #if LANG_CXX11 + FieldDescriptorProto(FieldDescriptorProto&& from) noexcept + : FieldDescriptorProto() { + *this = ::std::move(from); + } + inline FieldDescriptorProto& operator=(FieldDescriptorProto&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -1082,9 +1305,12 @@ class LIBPROTOBUF_EXPORT FieldDescriptorProto : public ::google::protobuf::Messa &_FieldDescriptorProto_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 5; + 6; void Swap(FieldDescriptorProto* other); + friend void swap(FieldDescriptorProto& a, FieldDescriptorProto& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -1375,11 +1601,24 @@ class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Messa CopyFrom(from); return *this; } + #if LANG_CXX11 + OneofDescriptorProto(OneofDescriptorProto&& from) noexcept + : OneofDescriptorProto() { + *this = ::std::move(from); + } + inline OneofDescriptorProto& operator=(OneofDescriptorProto&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -1392,9 +1631,12 @@ class LIBPROTOBUF_EXPORT OneofDescriptorProto : public ::google::protobuf::Messa &_OneofDescriptorProto_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 6; + 7; void Swap(OneofDescriptorProto* other); + friend void swap(OneofDescriptorProto& a, OneofDescriptorProto& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -1487,11 +1729,24 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag CopyFrom(from); return *this; } + #if LANG_CXX11 + EnumDescriptorProto(EnumDescriptorProto&& from) noexcept + : EnumDescriptorProto() { + *this = ::std::move(from); + } + inline EnumDescriptorProto& operator=(EnumDescriptorProto&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -1504,9 +1759,12 @@ class LIBPROTOBUF_EXPORT EnumDescriptorProto : public ::google::protobuf::Messag &_EnumDescriptorProto_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 7; + 8; void Swap(EnumDescriptorProto* other); + friend void swap(EnumDescriptorProto& a, EnumDescriptorProto& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -1612,11 +1870,24 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M CopyFrom(from); return *this; } + #if LANG_CXX11 + EnumValueDescriptorProto(EnumValueDescriptorProto&& from) noexcept + : EnumValueDescriptorProto() { + *this = ::std::move(from); + } + inline EnumValueDescriptorProto& operator=(EnumValueDescriptorProto&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -1629,9 +1900,12 @@ class LIBPROTOBUF_EXPORT EnumValueDescriptorProto : public ::google::protobuf::M &_EnumValueDescriptorProto_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 8; + 9; void Swap(EnumValueDescriptorProto* other); + friend void swap(EnumValueDescriptorProto& a, EnumValueDescriptorProto& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -1734,11 +2008,24 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes CopyFrom(from); return *this; } + #if LANG_CXX11 + ServiceDescriptorProto(ServiceDescriptorProto&& from) noexcept + : ServiceDescriptorProto() { + *this = ::std::move(from); + } + inline ServiceDescriptorProto& operator=(ServiceDescriptorProto&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -1751,9 +2038,12 @@ class LIBPROTOBUF_EXPORT ServiceDescriptorProto : public ::google::protobuf::Mes &_ServiceDescriptorProto_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 9; + 10; void Swap(ServiceDescriptorProto* other); + friend void swap(ServiceDescriptorProto& a, ServiceDescriptorProto& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -1859,11 +2149,24 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess CopyFrom(from); return *this; } + #if LANG_CXX11 + MethodDescriptorProto(MethodDescriptorProto&& from) noexcept + : MethodDescriptorProto() { + *this = ::std::move(from); + } + inline MethodDescriptorProto& operator=(MethodDescriptorProto&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -1876,9 +2179,12 @@ class LIBPROTOBUF_EXPORT MethodDescriptorProto : public ::google::protobuf::Mess &_MethodDescriptorProto_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 10; + 11; void Swap(MethodDescriptorProto* other); + friend void swap(MethodDescriptorProto& a, MethodDescriptorProto& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -2027,11 +2333,24 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p CopyFrom(from); return *this; } + #if LANG_CXX11 + FileOptions(FileOptions&& from) noexcept + : FileOptions() { + *this = ::std::move(from); + } + inline FileOptions& operator=(FileOptions&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -2044,9 +2363,12 @@ class LIBPROTOBUF_EXPORT FileOptions : public ::google::protobuf::Message /* @@p &_FileOptions_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 11; + 12; void Swap(FileOptions* other); + friend void swap(FileOptions& a, FileOptions& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -2369,11 +2691,24 @@ class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /* CopyFrom(from); return *this; } + #if LANG_CXX11 + MessageOptions(MessageOptions&& from) noexcept + : MessageOptions() { + *this = ::std::move(from); + } + inline MessageOptions& operator=(MessageOptions&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -2386,9 +2721,12 @@ class LIBPROTOBUF_EXPORT MessageOptions : public ::google::protobuf::Message /* &_MessageOptions_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 12; + 13; void Swap(MessageOptions* other); + friend void swap(MessageOptions& a, MessageOptions& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -2507,11 +2845,24 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@ CopyFrom(from); return *this; } + #if LANG_CXX11 + FieldOptions(FieldOptions&& from) noexcept + : FieldOptions() { + *this = ::std::move(from); + } + inline FieldOptions& operator=(FieldOptions&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -2524,9 +2875,12 @@ class LIBPROTOBUF_EXPORT FieldOptions : public ::google::protobuf::Message /* @@ &_FieldOptions_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 13; + 14; void Swap(FieldOptions* other); + friend void swap(FieldOptions& a, FieldOptions& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -2721,11 +3075,24 @@ class LIBPROTOBUF_EXPORT OneofOptions : public ::google::protobuf::Message /* @@ CopyFrom(from); return *this; } + #if LANG_CXX11 + OneofOptions(OneofOptions&& from) noexcept + : OneofOptions() { + *this = ::std::move(from); + } + inline OneofOptions& operator=(OneofOptions&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -2738,9 +3105,12 @@ class LIBPROTOBUF_EXPORT OneofOptions : public ::google::protobuf::Message /* @@ &_OneofOptions_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 14; + 15; void Swap(OneofOptions* other); + friend void swap(OneofOptions& a, OneofOptions& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -2819,11 +3189,24 @@ class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@p CopyFrom(from); return *this; } + #if LANG_CXX11 + EnumOptions(EnumOptions&& from) noexcept + : EnumOptions() { + *this = ::std::move(from); + } + inline EnumOptions& operator=(EnumOptions&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -2836,9 +3219,12 @@ class LIBPROTOBUF_EXPORT EnumOptions : public ::google::protobuf::Message /* @@p &_EnumOptions_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 15; + 16; void Swap(EnumOptions* other); + friend void swap(EnumOptions& a, EnumOptions& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -2937,11 +3323,24 @@ class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message / CopyFrom(from); return *this; } + #if LANG_CXX11 + EnumValueOptions(EnumValueOptions&& from) noexcept + : EnumValueOptions() { + *this = ::std::move(from); + } + inline EnumValueOptions& operator=(EnumValueOptions&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -2954,9 +3353,12 @@ class LIBPROTOBUF_EXPORT EnumValueOptions : public ::google::protobuf::Message / &_EnumValueOptions_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 16; + 17; void Swap(EnumValueOptions* other); + friend void swap(EnumValueOptions& a, EnumValueOptions& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -3045,11 +3447,24 @@ class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /* CopyFrom(from); return *this; } + #if LANG_CXX11 + ServiceOptions(ServiceOptions&& from) noexcept + : ServiceOptions() { + *this = ::std::move(from); + } + inline ServiceOptions& operator=(ServiceOptions&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -3062,9 +3477,12 @@ class LIBPROTOBUF_EXPORT ServiceOptions : public ::google::protobuf::Message /* &_ServiceOptions_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 17; + 18; void Swap(ServiceOptions* other); + friend void swap(ServiceOptions& a, ServiceOptions& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -3153,11 +3571,24 @@ class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @ CopyFrom(from); return *this; } + #if LANG_CXX11 + MethodOptions(MethodOptions&& from) noexcept + : MethodOptions() { + *this = ::std::move(from); + } + inline MethodOptions& operator=(MethodOptions&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -3170,9 +3601,12 @@ class LIBPROTOBUF_EXPORT MethodOptions : public ::google::protobuf::Message /* @ &_MethodOptions_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 18; + 19; void Swap(MethodOptions* other); + friend void swap(MethodOptions& a, MethodOptions& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -3299,11 +3733,24 @@ class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobu CopyFrom(from); return *this; } + #if LANG_CXX11 + UninterpretedOption_NamePart(UninterpretedOption_NamePart&& from) noexcept + : UninterpretedOption_NamePart() { + *this = ::std::move(from); + } + inline UninterpretedOption_NamePart& operator=(UninterpretedOption_NamePart&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -3316,9 +3763,12 @@ class LIBPROTOBUF_EXPORT UninterpretedOption_NamePart : public ::google::protobu &_UninterpretedOption_NamePart_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 19; + 20; void Swap(UninterpretedOption_NamePart* other); + friend void swap(UninterpretedOption_NamePart& a, UninterpretedOption_NamePart& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -3412,11 +3862,24 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag CopyFrom(from); return *this; } + #if LANG_CXX11 + UninterpretedOption(UninterpretedOption&& from) noexcept + : UninterpretedOption() { + *this = ::std::move(from); + } + inline UninterpretedOption& operator=(UninterpretedOption&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -3429,9 +3892,12 @@ class LIBPROTOBUF_EXPORT UninterpretedOption : public ::google::protobuf::Messag &_UninterpretedOption_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 20; + 21; void Swap(UninterpretedOption* other); + friend void swap(UninterpretedOption& a, UninterpretedOption& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -3593,11 +4059,24 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Me CopyFrom(from); return *this; } + #if LANG_CXX11 + SourceCodeInfo_Location(SourceCodeInfo_Location&& from) noexcept + : SourceCodeInfo_Location() { + *this = ::std::move(from); + } + inline SourceCodeInfo_Location& operator=(SourceCodeInfo_Location&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -3610,9 +4089,12 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo_Location : public ::google::protobuf::Me &_SourceCodeInfo_Location_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 21; + 22; void Swap(SourceCodeInfo_Location* other); + friend void swap(SourceCodeInfo_Location& a, SourceCodeInfo_Location& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -3762,11 +4244,24 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message /* CopyFrom(from); return *this; } + #if LANG_CXX11 + SourceCodeInfo(SourceCodeInfo&& from) noexcept + : SourceCodeInfo() { + *this = ::std::move(from); + } + inline SourceCodeInfo& operator=(SourceCodeInfo&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -3779,9 +4274,12 @@ class LIBPROTOBUF_EXPORT SourceCodeInfo : public ::google::protobuf::Message /* &_SourceCodeInfo_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 22; + 23; void Swap(SourceCodeInfo* other); + friend void swap(SourceCodeInfo& a, SourceCodeInfo& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -3859,11 +4357,24 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobu CopyFrom(from); return *this; } + #if LANG_CXX11 + GeneratedCodeInfo_Annotation(GeneratedCodeInfo_Annotation&& from) noexcept + : GeneratedCodeInfo_Annotation() { + *this = ::std::move(from); + } + inline GeneratedCodeInfo_Annotation& operator=(GeneratedCodeInfo_Annotation&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -3876,9 +4387,12 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo_Annotation : public ::google::protobu &_GeneratedCodeInfo_Annotation_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 23; + 24; void Swap(GeneratedCodeInfo_Annotation* other); + friend void swap(GeneratedCodeInfo_Annotation& a, GeneratedCodeInfo_Annotation& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -3993,11 +4507,24 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo : public ::google::protobuf::Message CopyFrom(from); return *this; } + #if LANG_CXX11 + GeneratedCodeInfo(GeneratedCodeInfo&& from) noexcept + : GeneratedCodeInfo() { + *this = ::std::move(from); + } + inline GeneratedCodeInfo& operator=(GeneratedCodeInfo&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const { return _internal_metadata_.unknown_fields(); } - inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() { return _internal_metadata_.mutable_unknown_fields(); } @@ -4010,9 +4537,12 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo : public ::google::protobuf::Message &_GeneratedCodeInfo_default_instance_); } static PROTOBUF_CONSTEXPR int const kIndexInFileMessages = - 24; + 25; void Swap(GeneratedCodeInfo* other); + friend void swap(GeneratedCodeInfo& a, GeneratedCodeInfo& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -4083,6 +4613,10 @@ class LIBPROTOBUF_EXPORT GeneratedCodeInfo : public ::google::protobuf::Message // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ // FileDescriptorSet // repeated .google.protobuf.FileDescriptorProto file = 1; @@ -4509,9 +5043,10 @@ inline void FileDescriptorProto::clear_options() { clear_has_options(); } inline const ::google::protobuf::FileOptions& FileDescriptorProto::options() const { + const ::google::protobuf::FileOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::FileOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::FileOptions*>( + &::google::protobuf::_FileOptions_default_instance_); } inline ::google::protobuf::FileOptions* FileDescriptorProto::mutable_options() { set_has_options(); @@ -4554,9 +5089,10 @@ inline void FileDescriptorProto::clear_source_code_info() { clear_has_source_code_info(); } inline const ::google::protobuf::SourceCodeInfo& FileDescriptorProto::source_code_info() const { + const ::google::protobuf::SourceCodeInfo* p = source_code_info_; // @@protoc_insertion_point(field_get:google.protobuf.FileDescriptorProto.source_code_info) - return source_code_info_ != NULL ? *source_code_info_ - : *::google::protobuf::SourceCodeInfo::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceCodeInfo*>( + &::google::protobuf::_SourceCodeInfo_default_instance_); } inline ::google::protobuf::SourceCodeInfo* FileDescriptorProto::mutable_source_code_info() { set_has_source_code_info(); @@ -4653,13 +5189,13 @@ inline void FileDescriptorProto::set_allocated_syntax(::std::string* syntax) { // optional int32 start = 1; inline bool DescriptorProto_ExtensionRange::has_start() const { - return (_has_bits_[0] & 0x00000001u) != 0; + return (_has_bits_[0] & 0x00000002u) != 0; } inline void DescriptorProto_ExtensionRange::set_has_start() { - _has_bits_[0] |= 0x00000001u; + _has_bits_[0] |= 0x00000002u; } inline void DescriptorProto_ExtensionRange::clear_has_start() { - _has_bits_[0] &= ~0x00000001u; + _has_bits_[0] &= ~0x00000002u; } inline void DescriptorProto_ExtensionRange::clear_start() { start_ = 0; @@ -4677,13 +5213,13 @@ inline void DescriptorProto_ExtensionRange::set_start(::google::protobuf::int32 // optional int32 end = 2; inline bool DescriptorProto_ExtensionRange::has_end() const { - return (_has_bits_[0] & 0x00000002u) != 0; + return (_has_bits_[0] & 0x00000004u) != 0; } inline void DescriptorProto_ExtensionRange::set_has_end() { - _has_bits_[0] |= 0x00000002u; + _has_bits_[0] |= 0x00000004u; } inline void DescriptorProto_ExtensionRange::clear_has_end() { - _has_bits_[0] &= ~0x00000002u; + _has_bits_[0] &= ~0x00000004u; } inline void DescriptorProto_ExtensionRange::clear_end() { end_ = 0; @@ -4699,6 +5235,52 @@ inline void DescriptorProto_ExtensionRange::set_end(::google::protobuf::int32 va // @@protoc_insertion_point(field_set:google.protobuf.DescriptorProto.ExtensionRange.end) } +// optional .google.protobuf.ExtensionRangeOptions options = 3; +inline bool DescriptorProto_ExtensionRange::has_options() const { + return (_has_bits_[0] & 0x00000001u) != 0; +} +inline void DescriptorProto_ExtensionRange::set_has_options() { + _has_bits_[0] |= 0x00000001u; +} +inline void DescriptorProto_ExtensionRange::clear_has_options() { + _has_bits_[0] &= ~0x00000001u; +} +inline void DescriptorProto_ExtensionRange::clear_options() { + if (options_ != NULL) options_->::google::protobuf::ExtensionRangeOptions::Clear(); + clear_has_options(); +} +inline const ::google::protobuf::ExtensionRangeOptions& DescriptorProto_ExtensionRange::options() const { + const ::google::protobuf::ExtensionRangeOptions* p = options_; + // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.ExtensionRange.options) + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::ExtensionRangeOptions*>( + &::google::protobuf::_ExtensionRangeOptions_default_instance_); +} +inline ::google::protobuf::ExtensionRangeOptions* DescriptorProto_ExtensionRange::mutable_options() { + set_has_options(); + if (options_ == NULL) { + options_ = new ::google::protobuf::ExtensionRangeOptions; + } + // @@protoc_insertion_point(field_mutable:google.protobuf.DescriptorProto.ExtensionRange.options) + return options_; +} +inline ::google::protobuf::ExtensionRangeOptions* DescriptorProto_ExtensionRange::release_options() { + // @@protoc_insertion_point(field_release:google.protobuf.DescriptorProto.ExtensionRange.options) + clear_has_options(); + ::google::protobuf::ExtensionRangeOptions* temp = options_; + options_ = NULL; + return temp; +} +inline void DescriptorProto_ExtensionRange::set_allocated_options(::google::protobuf::ExtensionRangeOptions* options) { + delete options_; + options_ = options; + if (options) { + set_has_options(); + } else { + clear_has_options(); + } + // @@protoc_insertion_point(field_set_allocated:google.protobuf.DescriptorProto.ExtensionRange.options) +} + // ------------------------------------------------------------------- // DescriptorProto_ReservedRange @@ -5013,9 +5595,10 @@ inline void DescriptorProto::clear_options() { clear_has_options(); } inline const ::google::protobuf::MessageOptions& DescriptorProto::options() const { + const ::google::protobuf::MessageOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.DescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::MessageOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::MessageOptions*>( + &::google::protobuf::_MessageOptions_default_instance_); } inline ::google::protobuf::MessageOptions* DescriptorProto::mutable_options() { set_has_options(); @@ -5144,6 +5727,40 @@ DescriptorProto::mutable_reserved_name() { // ------------------------------------------------------------------- +// ExtensionRangeOptions + +// repeated .google.protobuf.UninterpretedOption uninterpreted_option = 999; +inline int ExtensionRangeOptions::uninterpreted_option_size() const { + return uninterpreted_option_.size(); +} +inline void ExtensionRangeOptions::clear_uninterpreted_option() { + uninterpreted_option_.Clear(); +} +inline const ::google::protobuf::UninterpretedOption& ExtensionRangeOptions::uninterpreted_option(int index) const { + // @@protoc_insertion_point(field_get:google.protobuf.ExtensionRangeOptions.uninterpreted_option) + return uninterpreted_option_.Get(index); +} +inline ::google::protobuf::UninterpretedOption* ExtensionRangeOptions::mutable_uninterpreted_option(int index) { + // @@protoc_insertion_point(field_mutable:google.protobuf.ExtensionRangeOptions.uninterpreted_option) + return uninterpreted_option_.Mutable(index); +} +inline ::google::protobuf::UninterpretedOption* ExtensionRangeOptions::add_uninterpreted_option() { + // @@protoc_insertion_point(field_add:google.protobuf.ExtensionRangeOptions.uninterpreted_option) + return uninterpreted_option_.Add(); +} +inline ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >* +ExtensionRangeOptions::mutable_uninterpreted_option() { + // @@protoc_insertion_point(field_mutable_list:google.protobuf.ExtensionRangeOptions.uninterpreted_option) + return &uninterpreted_option_; +} +inline const ::google::protobuf::RepeatedPtrField< ::google::protobuf::UninterpretedOption >& +ExtensionRangeOptions::uninterpreted_option() const { + // @@protoc_insertion_point(field_list:google.protobuf.ExtensionRangeOptions.uninterpreted_option) + return uninterpreted_option_; +} + +// ------------------------------------------------------------------- + // FieldDescriptorProto // optional string name = 1; @@ -5574,9 +6191,10 @@ inline void FieldDescriptorProto::clear_options() { clear_has_options(); } inline const ::google::protobuf::FieldOptions& FieldDescriptorProto::options() const { + const ::google::protobuf::FieldOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.FieldDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::FieldOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::FieldOptions*>( + &::google::protobuf::_FieldOptions_default_instance_); } inline ::google::protobuf::FieldOptions* FieldDescriptorProto::mutable_options() { set_has_options(); @@ -5686,9 +6304,10 @@ inline void OneofDescriptorProto::clear_options() { clear_has_options(); } inline const ::google::protobuf::OneofOptions& OneofDescriptorProto::options() const { + const ::google::protobuf::OneofOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.OneofDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::OneofOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::OneofOptions*>( + &::google::protobuf::_OneofOptions_default_instance_); } inline ::google::protobuf::OneofOptions* OneofDescriptorProto::mutable_options() { set_has_options(); @@ -5828,9 +6447,10 @@ inline void EnumDescriptorProto::clear_options() { clear_has_options(); } inline const ::google::protobuf::EnumOptions& EnumDescriptorProto::options() const { + const ::google::protobuf::EnumOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.EnumDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::EnumOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::EnumOptions*>( + &::google::protobuf::_EnumOptions_default_instance_); } inline ::google::protobuf::EnumOptions* EnumDescriptorProto::mutable_options() { set_has_options(); @@ -5964,9 +6584,10 @@ inline void EnumValueDescriptorProto::clear_options() { clear_has_options(); } inline const ::google::protobuf::EnumValueOptions& EnumValueDescriptorProto::options() const { + const ::google::protobuf::EnumValueOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.EnumValueDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::EnumValueOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::EnumValueOptions*>( + &::google::protobuf::_EnumValueOptions_default_instance_); } inline ::google::protobuf::EnumValueOptions* EnumValueDescriptorProto::mutable_options() { set_has_options(); @@ -6106,9 +6727,10 @@ inline void ServiceDescriptorProto::clear_options() { clear_has_options(); } inline const ::google::protobuf::ServiceOptions& ServiceDescriptorProto::options() const { + const ::google::protobuf::ServiceOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.ServiceDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::ServiceOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::ServiceOptions*>( + &::google::protobuf::_ServiceOptions_default_instance_); } inline ::google::protobuf::ServiceOptions* ServiceDescriptorProto::mutable_options() { set_has_options(); @@ -6344,9 +6966,10 @@ inline void MethodDescriptorProto::clear_options() { clear_has_options(); } inline const ::google::protobuf::MethodOptions& MethodDescriptorProto::options() const { + const ::google::protobuf::MethodOptions* p = options_; // @@protoc_insertion_point(field_get:google.protobuf.MethodDescriptorProto.options) - return options_ != NULL ? *options_ - : *::google::protobuf::MethodOptions::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::MethodOptions*>( + &::google::protobuf::_MethodOptions_default_instance_); } inline ::google::protobuf::MethodOptions* MethodDescriptorProto::mutable_options() { set_has_options(); @@ -8597,6 +9220,9 @@ GeneratedCodeInfo::annotation() const { return annotation_; } +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // ------------------------------------------------------------------- @@ -8646,6 +9272,8 @@ GeneratedCodeInfo::annotation() const { // ------------------------------------------------------------------- +// ------------------------------------------------------------------- + // @@protoc_insertion_point(namespace_scope) @@ -8653,7 +9281,6 @@ GeneratedCodeInfo::annotation() const { } // namespace protobuf } // namespace google -#ifndef SWIG namespace google { namespace protobuf { @@ -8690,7 +9317,6 @@ inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::MethodOption } // namespace protobuf } // namespace google -#endif // SWIG // @@protoc_insertion_point(global_scope) diff --git a/src/google/protobuf/descriptor.proto b/src/google/protobuf/descriptor.proto index f859c429..05028789 100644 --- a/src/google/protobuf/descriptor.proto +++ b/src/google/protobuf/descriptor.proto @@ -101,6 +101,8 @@ message DescriptorProto { message ExtensionRange { optional int32 start = 1; optional int32 end = 2; + + optional ExtensionRangeOptions options = 3; } repeated ExtensionRange extension_range = 5; @@ -121,6 +123,14 @@ message DescriptorProto { repeated string reserved_name = 10; } +message ExtensionRangeOptions { + // The parser stores options it doesn't recognize here. See above. + repeated UninterpretedOption uninterpreted_option = 999; + + // Clients can define custom options in extensions of this message. See above. + extensions 1000 to max; +} + // Describes a field within a message. message FieldDescriptorProto { enum Type { @@ -477,13 +487,15 @@ message FieldOptions { // The jstype option determines the JavaScript type used for values of the // field. The option is permitted only for 64 bit integral and fixed types - // (int64, uint64, sint64, fixed64, sfixed64). By default these types are - // represented as JavaScript strings. This avoids loss of precision that can - // happen when a large value is converted to a floating point JavaScript - // numbers. Specifying JS_NUMBER for the jstype causes the generated - // JavaScript code to use the JavaScript "number" type instead of strings. - // This option is an enum to permit additional types to be added, - // e.g. goog.math.Integer. + // (int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING + // is represented as JavaScript string, which avoids loss of precision that + // can happen when a large value is converted to a floating point JavaScript. + // Specifying JS_NUMBER for the jstype causes the generated JavaScript code to + // use the JavaScript "number" type. The behavior of the default option + // JS_NORMAL is implementation dependent. + // + // This option is an enum to permit additional types to be added, e.g. + // goog.math.Integer. optional JSType jstype = 6 [default = JS_NORMAL]; enum JSType { // Use the default type. diff --git a/src/google/protobuf/descriptor_database.cc b/src/google/protobuf/descriptor_database.cc index 4e46b2a8..ba85ef13 100644 --- a/src/google/protobuf/descriptor_database.cc +++ b/src/google/protobuf/descriptor_database.cc @@ -39,8 +39,9 @@ #include <google/protobuf/descriptor.pb.h> #include <google/protobuf/wire_format_lite_inl.h> #include <google/protobuf/stubs/strutil.h> -#include <google/protobuf/stubs/stl_util.h> + #include <google/protobuf/stubs/map_util.h> +#include <google/protobuf/stubs/stl_util.h> namespace google { namespace protobuf { @@ -230,7 +231,7 @@ bool SimpleDescriptorDatabase::DescriptorIndex<Value>::IsSubSymbol( const string& sub_symbol, const string& super_symbol) { return sub_symbol == super_symbol || (HasPrefixString(super_symbol, sub_symbol) && - super_symbol[sub_symbol.size()] == '.'); + super_symbol[sub_symbol.size()] == '.'); } template <typename Value> diff --git a/src/google/protobuf/drop_unknown_fields_test.cc b/src/google/protobuf/drop_unknown_fields_test.cc index 6f16dc53..f2f2f749 100644 --- a/src/google/protobuf/drop_unknown_fields_test.cc +++ b/src/google/protobuf/drop_unknown_fields_test.cc @@ -35,6 +35,7 @@ #include <google/protobuf/unittest_drop_unknown_fields.pb.h> #include <google/protobuf/dynamic_message.h> +#include <google/protobuf/message_lite.h> #include <gtest/gtest.h> namespace google { @@ -43,7 +44,8 @@ using unittest_drop_unknown_fields::FooWithExtraFields; namespace protobuf { -TEST(DropUnknownFieldsTest, GeneratedMessage) { +TEST(DropUnknownFieldsTest, GeneratedMessageDefaultDrop) { + ::google::protobuf::internal::SetProto3PreserveUnknownsDefault(false); FooWithExtraFields foo_with_extra_fields; foo_with_extra_fields.set_int32_value(1); foo_with_extra_fields.set_enum_value(FooWithExtraFields::QUX); @@ -54,8 +56,6 @@ TEST(DropUnknownFieldsTest, GeneratedMessage) { EXPECT_EQ(1, foo.int32_value()); EXPECT_EQ(static_cast<int>(FooWithExtraFields::QUX), static_cast<int>(foo.enum_value())); - // We don't generate unknown field accessors but the UnknownFieldSet is - // still exposed through reflection API. EXPECT_TRUE(foo.GetReflection()->GetUnknownFields(foo).empty()); ASSERT_TRUE(foo_with_extra_fields.ParseFromString(foo.SerializeAsString())); @@ -65,7 +65,29 @@ TEST(DropUnknownFieldsTest, GeneratedMessage) { EXPECT_EQ(0, foo_with_extra_fields.extra_int32_value()); } -TEST(DropUnknownFieldsTest, DynamicMessage) { +TEST(DropUnknownFieldsTest, GeneratedMessageDefaultPreserve) { + ::google::protobuf::internal::SetProto3PreserveUnknownsDefault(true); + FooWithExtraFields foo_with_extra_fields; + foo_with_extra_fields.set_int32_value(1); + foo_with_extra_fields.set_enum_value(FooWithExtraFields::QUX); + foo_with_extra_fields.set_extra_int32_value(2); + + Foo foo; + ASSERT_TRUE(foo.ParseFromString(foo_with_extra_fields.SerializeAsString())); + EXPECT_EQ(1, foo.int32_value()); + EXPECT_EQ(static_cast<int>(FooWithExtraFields::QUX), + static_cast<int>(foo.enum_value())); + EXPECT_FALSE(foo.GetReflection()->GetUnknownFields(foo).empty()); + + ASSERT_TRUE(foo_with_extra_fields.ParseFromString(foo.SerializeAsString())); + EXPECT_EQ(1, foo_with_extra_fields.int32_value()); + EXPECT_EQ(FooWithExtraFields::QUX, foo_with_extra_fields.enum_value()); + // The "extra_int32_value" field should not be lost. + EXPECT_EQ(2, foo_with_extra_fields.extra_int32_value()); +} + +TEST(DropUnknownFieldsTest, DynamicMessageDefaultDrop) { + internal::SetProto3PreserveUnknownsDefault(false); FooWithExtraFields foo_with_extra_fields; foo_with_extra_fields.set_int32_value(1); foo_with_extra_fields.set_enum_value(FooWithExtraFields::QUX); @@ -84,5 +106,25 @@ TEST(DropUnknownFieldsTest, DynamicMessage) { EXPECT_EQ(0, foo_with_extra_fields.extra_int32_value()); } +TEST(DropUnknownFieldsTest, DynamicMessageDefaultPreserve) { + internal::SetProto3PreserveUnknownsDefault(true); + FooWithExtraFields foo_with_extra_fields; + foo_with_extra_fields.set_int32_value(1); + foo_with_extra_fields.set_enum_value(FooWithExtraFields::QUX); + foo_with_extra_fields.set_extra_int32_value(2); + + google::protobuf::DynamicMessageFactory factory; + google::protobuf::scoped_ptr<google::protobuf::Message> foo( + factory.GetPrototype(Foo::descriptor())->New()); + ASSERT_TRUE(foo->ParseFromString(foo_with_extra_fields.SerializeAsString())); + EXPECT_FALSE(foo->GetReflection()->GetUnknownFields(*foo).empty()); + + ASSERT_TRUE(foo_with_extra_fields.ParseFromString(foo->SerializeAsString())); + EXPECT_EQ(1, foo_with_extra_fields.int32_value()); + EXPECT_EQ(FooWithExtraFields::QUX, foo_with_extra_fields.enum_value()); + // The "extra_int32_value" field should not be lost. + EXPECT_EQ(2, foo_with_extra_fields.extra_int32_value()); +} + } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/duration.pb.cc b/src/google/protobuf/duration.pb.cc index ae1a5e08..46812a05 100644 --- a/src/google/protobuf/duration.pb.cc +++ b/src/google/protobuf/duration.pb.cc @@ -32,20 +32,20 @@ namespace { } // namespace PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField - const TableStruct::entries[] = { + const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField - const TableStruct::aux[] = { + const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ::google::protobuf::internal::AuxillaryParseTableField(), }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const - TableStruct::schema[] = { + TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { NULL, NULL, 0, -1, -1, false }, }; -const ::google::protobuf::uint32 TableStruct::offsets[] = { +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, _internal_metadata_), ~0u, // no _extensions_ @@ -54,8 +54,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, seconds_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Duration, nanos_), }; - -static const ::google::protobuf::internal::MigrationSchema schemas[] = { +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { 0, -1, sizeof(Duration)}, }; @@ -85,12 +84,6 @@ void protobuf_RegisterTypes(const ::std::string&) { } } // namespace - -void TableStruct::Shutdown() { - _Duration_default_instance_.Shutdown(); - delete file_level_metadata[0].reflection; -} - void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -104,7 +97,7 @@ void InitDefaults() { } void AddDescriptorsImpl() { InitDefaults(); - static const char descriptor[] = { + static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { "\n\036google/protobuf/duration.proto\022\017google" ".protobuf\"*\n\010Duration\022\017\n\007seconds\030\001 \001(\003\022\r" "\n\005nanos\030\002 \001(\005B|\n\023com.google.protobufB\rDu" @@ -116,14 +109,13 @@ void AddDescriptorsImpl() { descriptor, 227); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/duration.proto", &protobuf_RegisterTypes); - ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); } void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -151,9 +143,7 @@ Duration::Duration() Duration::Duration(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fduration_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Duration) @@ -182,6 +172,7 @@ Duration::~Duration() { void Duration::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -215,8 +206,13 @@ Duration* Duration::New(::google::protobuf::Arena* arena) const { void Duration::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Duration) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + ::memset(&seconds_, 0, reinterpret_cast<char*>(&nanos_) - reinterpret_cast<char*>(&seconds_) + sizeof(nanos_)); + _internal_metadata_.Clear(); } bool Duration::MergePartialFromCodedStream( @@ -232,7 +228,7 @@ bool Duration::MergePartialFromCodedStream( // int64 seconds = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>( @@ -246,7 +242,7 @@ bool Duration::MergePartialFromCodedStream( // int32 nanos = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -259,12 +255,11 @@ bool Duration::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -294,6 +289,10 @@ void Duration::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->nanos(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Duration) } @@ -313,6 +312,10 @@ void Duration::SerializeWithCachedSizes( target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->nanos(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Duration) return target; } @@ -321,6 +324,11 @@ size_t Duration::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Duration) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // int64 seconds = 1; if (this->seconds() != 0) { total_size += 1 + @@ -410,9 +418,11 @@ void Duration::UnsafeArenaSwap(Duration* other) { InternalSwap(other); } void Duration::InternalSwap(Duration* other) { - std::swap(seconds_, other->seconds_); - std::swap(nanos_, other->nanos_); - std::swap(_cached_size_, other->_cached_size_); + using std::swap; + swap(seconds_, other->seconds_); + swap(nanos_, other->nanos_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Duration::GetMetadata() const { diff --git a/src/google/protobuf/duration.pb.h b/src/google/protobuf/duration.pb.h index 34873d97..71809ff6 100644 --- a/src/google/protobuf/duration.pb.h +++ b/src/google/protobuf/duration.pb.h @@ -48,8 +48,9 @@ struct LIBPROTOBUF_EXPORT TableStruct { static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; static void InitDefaultsImpl(); - static void Shutdown(); }; void LIBPROTOBUF_EXPORT AddDescriptors(); void LIBPROTOBUF_EXPORT InitDefaults(); @@ -68,7 +69,21 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot CopyFrom(from); return *this; } + #if LANG_CXX11 + Duration(Duration&& from) noexcept + : Duration() { + *this = ::std::move(from); + } + inline Duration& operator=(Duration&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -87,6 +102,9 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot void UnsafeArenaSwap(Duration* other); void Swap(Duration* other); + friend void swap(Duration& a, Duration& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -149,7 +167,7 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::int64 seconds_; @@ -163,6 +181,10 @@ class LIBPROTOBUF_EXPORT Duration : public ::google::protobuf::Message /* @@prot // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ // Duration // int64 seconds = 1; @@ -193,6 +215,9 @@ inline void Duration::set_nanos(::google::protobuf::int32 value) { // @@protoc_insertion_point(field_set:google.protobuf.Duration.nanos) } +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // @@protoc_insertion_point(namespace_scope) diff --git a/src/google/protobuf/dynamic_message.cc b/src/google/protobuf/dynamic_message.cc index ee8113e3..cdd43243 100644 --- a/src/google/protobuf/dynamic_message.cc +++ b/src/google/protobuf/dynamic_message.cc @@ -250,6 +250,10 @@ class DynamicMessage : public Message { }; DynamicMessage(const TypeInfo* type_info); + + // This should only be used by GetPrototypeNoLock() to avoid dead lock. + DynamicMessage(const TypeInfo* type_info, bool lock_factory); + ~DynamicMessage(); // Called on the prototype after construction to initialize message fields. @@ -280,7 +284,8 @@ class DynamicMessage : public Message { private: GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMessage); DynamicMessage(const TypeInfo* type_info, ::google::protobuf::Arena* arena); - void SharedCtor(); + + void SharedCtor(bool lock_factory); inline bool is_prototype() const { return type_info_->prototype == this || @@ -304,17 +309,22 @@ class DynamicMessage : public Message { DynamicMessage::DynamicMessage(const TypeInfo* type_info) : type_info_(type_info), cached_byte_size_(0) { - SharedCtor(); + SharedCtor(true); } DynamicMessage::DynamicMessage(const TypeInfo* type_info, ::google::protobuf::Arena* arena) : type_info_(type_info), cached_byte_size_(0) { - SharedCtor(); + SharedCtor(true); +} + +DynamicMessage::DynamicMessage(const TypeInfo* type_info, bool lock_factory) + : type_info_(type_info), cached_byte_size_(0) { + SharedCtor(lock_factory); } -void DynamicMessage::SharedCtor() { +void DynamicMessage::SharedCtor(bool lock_factory) { // We need to call constructors for various fields manually and set // default values where appropriate. We use placement new to call // constructors. If you haven't heard of placement new, I suggest Googling @@ -398,8 +408,17 @@ void DynamicMessage::SharedCtor() { new(field_ptr) Message*(NULL); } else { if (IsMapFieldInApi(field)) { - new (field_ptr) DynamicMapField( - type_info_->factory->GetPrototypeNoLock(field->message_type())); + // We need to lock in most cases to avoid data racing. Only not lock + // when the constructor is called inside GetPrototype(), in which + // case we have already locked the factory. + if (lock_factory) { + new (field_ptr) DynamicMapField( + type_info_->factory->GetPrototype(field->message_type())); + } else { + new (field_ptr) + DynamicMapField(type_info_->factory->GetPrototypeNoLock( + field->message_type())); + } } else { new (field_ptr) RepeatedPtrField<Message>(); } @@ -751,7 +770,10 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock( // map). To break the cyclic dependency, we have to assgin the address of // prototype into type_info first. type_info->prototype = static_cast<DynamicMessage*>(base); - DynamicMessage* prototype = new(base) DynamicMessage(type_info); + + // We have already locked the factory so we should not lock in the constructor + // of dynamic message to avoid dead lock. + DynamicMessage* prototype = new (base) DynamicMessage(type_info, false); if (type->oneof_decl_count() > 0 || num_weak_fields > 0) { // Construct default oneof instance. diff --git a/src/google/protobuf/dynamic_message.h b/src/google/protobuf/dynamic_message.h index 816170ea..05722171 100644 --- a/src/google/protobuf/dynamic_message.h +++ b/src/google/protobuf/dynamic_message.h @@ -166,14 +166,14 @@ class LIBPROTOBUF_EXPORT DynamicMapSorter { } GOOGLE_DCHECK_EQ(result.size(), static_cast<size_t>(i)); MapEntryMessageComparator comparator(field->message_type()); - std::sort(result.begin(), result.end(), comparator); + std::stable_sort(result.begin(), result.end(), comparator); // Complain if the keys aren't in ascending order. #ifndef NDEBUG for (int j = 1; j < map_size; j++) { if (!comparator(result[j - 1], result[j])) { GOOGLE_LOG(ERROR) << (comparator(result[j], result[j - 1]) ? - "internal error in map key sorting" : - "map keys are not unique"); + "internal error in map key sorting" : + "map keys are not unique"); } } #endif diff --git a/src/google/protobuf/empty.pb.cc b/src/google/protobuf/empty.pb.cc index 71195056..6aec108f 100644 --- a/src/google/protobuf/empty.pb.cc +++ b/src/google/protobuf/empty.pb.cc @@ -32,28 +32,27 @@ namespace { } // namespace PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField - const TableStruct::entries[] = { + const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField - const TableStruct::aux[] = { + const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ::google::protobuf::internal::AuxillaryParseTableField(), }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const - TableStruct::schema[] = { + TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { NULL, NULL, 0, -1, -1, false }, }; -const ::google::protobuf::uint32 TableStruct::offsets[] = { +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Empty, _internal_metadata_), ~0u, // no _extensions_ ~0u, // no _oneof_case_ ~0u, // no _weak_field_map_ }; - -static const ::google::protobuf::internal::MigrationSchema schemas[] = { +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { 0, -1, sizeof(Empty)}, }; @@ -83,12 +82,6 @@ void protobuf_RegisterTypes(const ::std::string&) { } } // namespace - -void TableStruct::Shutdown() { - _Empty_default_instance_.Shutdown(); - delete file_level_metadata[0].reflection; -} - void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -102,7 +95,7 @@ void InitDefaults() { } void AddDescriptorsImpl() { InitDefaults(); - static const char descriptor[] = { + static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { "\n\033google/protobuf/empty.proto\022\017google.pr" "otobuf\"\007\n\005EmptyBv\n\023com.google.protobufB\n" "EmptyProtoP\001Z\'github.com/golang/protobuf" @@ -113,14 +106,13 @@ void AddDescriptorsImpl() { descriptor, 183); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/empty.proto", &protobuf_RegisterTypes); - ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); } void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -146,9 +138,7 @@ Empty::Empty() Empty::Empty(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fempty_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Empty) @@ -172,6 +162,7 @@ Empty::~Empty() { void Empty::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -205,6 +196,11 @@ Empty* Empty::New(::google::protobuf::Arena* arena) const { void Empty::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Empty) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _internal_metadata_.Clear(); } bool Empty::MergePartialFromCodedStream( @@ -217,12 +213,11 @@ bool Empty::MergePartialFromCodedStream( tag = p.first; if (!p.second) goto handle_unusual; handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); } success: // @@protoc_insertion_point(parse_success:google.protobuf.Empty) @@ -239,6 +234,10 @@ void Empty::SerializeWithCachedSizes( ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Empty) } @@ -248,6 +247,10 @@ void Empty::SerializeWithCachedSizes( ::google::protobuf::uint32 cached_has_bits = 0; (void) cached_has_bits; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Empty) return target; } @@ -256,6 +259,11 @@ size_t Empty::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Empty) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } int cached_size = ::google::protobuf::internal::ToCachedSize(total_size); GOOGLE_SAFE_CONCURRENT_WRITES_BEGIN(); _cached_size_ = cached_size; @@ -325,7 +333,9 @@ void Empty::UnsafeArenaSwap(Empty* other) { InternalSwap(other); } void Empty::InternalSwap(Empty* other) { - std::swap(_cached_size_, other->_cached_size_); + using std::swap; + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Empty::GetMetadata() const { diff --git a/src/google/protobuf/empty.pb.h b/src/google/protobuf/empty.pb.h index f28dc19b..18cd3bfc 100644 --- a/src/google/protobuf/empty.pb.h +++ b/src/google/protobuf/empty.pb.h @@ -48,8 +48,9 @@ struct LIBPROTOBUF_EXPORT TableStruct { static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; static void InitDefaultsImpl(); - static void Shutdown(); }; void LIBPROTOBUF_EXPORT AddDescriptors(); void LIBPROTOBUF_EXPORT InitDefaults(); @@ -68,7 +69,21 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_ CopyFrom(from); return *this; } + #if LANG_CXX11 + Empty(Empty&& from) noexcept + : Empty() { + *this = ::std::move(from); + } + inline Empty& operator=(Empty&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -87,6 +102,9 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_ void UnsafeArenaSwap(Empty* other); void Swap(Empty* other); + friend void swap(Empty& a, Empty& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -137,7 +155,7 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_ private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; mutable int _cached_size_; @@ -149,8 +167,15 @@ class LIBPROTOBUF_EXPORT Empty : public ::google::protobuf::Message /* @@protoc_ // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ // Empty +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // @@protoc_insertion_point(namespace_scope) diff --git a/src/google/protobuf/extension_set.h b/src/google/protobuf/extension_set.h index cf5f652d..6f47c4a6 100644 --- a/src/google/protobuf/extension_set.h +++ b/src/google/protobuf/extension_set.h @@ -438,6 +438,11 @@ class LIBPROTOBUF_EXPORT ExtensionSet { // SpaceUsed()). size_t SpaceUsedExcludingSelfLong() const; + // This method just calls SpaceUsedExcludingSelfLong() but it can not be + // inlined because the definition of SpaceUsedExcludingSelfLong() is not + // included in lite runtime and when an inline method refers to it MSVC + // will complain about unresolved symbols when building the lite runtime + // as .dll. int SpaceUsedExcludingSelf() const; private: diff --git a/src/google/protobuf/extension_set_unittest.cc b/src/google/protobuf/extension_set_unittest.cc index 772d2734..3e71b253 100644 --- a/src/google/protobuf/extension_set_unittest.cc +++ b/src/google/protobuf/extension_set_unittest.cc @@ -32,6 +32,7 @@ // Based on original Protocol Buffers design by // Sanjay Ghemawat, Jeff Dean, and others. + #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/extension_set.h> #include <google/protobuf/unittest.pb.h> diff --git a/src/google/protobuf/field_mask.pb.cc b/src/google/protobuf/field_mask.pb.cc index 094c4cc9..a3ec2d2b 100644 --- a/src/google/protobuf/field_mask.pb.cc +++ b/src/google/protobuf/field_mask.pb.cc @@ -32,20 +32,20 @@ namespace { } // namespace PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField - const TableStruct::entries[] = { + const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField - const TableStruct::aux[] = { + const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ::google::protobuf::internal::AuxillaryParseTableField(), }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const - TableStruct::schema[] = { + TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { NULL, NULL, 0, -1, -1, false }, }; -const ::google::protobuf::uint32 TableStruct::offsets[] = { +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldMask, _internal_metadata_), ~0u, // no _extensions_ @@ -53,8 +53,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(FieldMask, paths_), }; - -static const ::google::protobuf::internal::MigrationSchema schemas[] = { +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { 0, -1, sizeof(FieldMask)}, }; @@ -84,12 +83,6 @@ void protobuf_RegisterTypes(const ::std::string&) { } } // namespace - -void TableStruct::Shutdown() { - _FieldMask_default_instance_.Shutdown(); - delete file_level_metadata[0].reflection; -} - void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -103,7 +96,7 @@ void InitDefaults() { } void AddDescriptorsImpl() { InitDefaults(); - static const char descriptor[] = { + static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { "\n google/protobuf/field_mask.proto\022\017goog" "le.protobuf\"\032\n\tFieldMask\022\r\n\005paths\030\001 \003(\tB" "\211\001\n\023com.google.protobufB\016FieldMaskProtoP" @@ -115,14 +108,13 @@ void AddDescriptorsImpl() { descriptor, 227); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/field_mask.proto", &protobuf_RegisterTypes); - ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); } void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -192,7 +184,12 @@ FieldMask* FieldMask::New(::google::protobuf::Arena* arena) const { void FieldMask::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FieldMask) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + paths_.Clear(); + _internal_metadata_.Clear(); } bool FieldMask::MergePartialFromCodedStream( @@ -208,7 +205,7 @@ bool FieldMask::MergePartialFromCodedStream( // repeated string paths = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->add_paths())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -224,12 +221,11 @@ bool FieldMask::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -259,6 +255,10 @@ void FieldMask::SerializeWithCachedSizes( 1, this->paths(i), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.FieldMask) } @@ -278,6 +278,10 @@ void FieldMask::SerializeWithCachedSizes( WriteStringToArray(1, this->paths(i), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.FieldMask) return target; } @@ -286,6 +290,11 @@ size_t FieldMask::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FieldMask) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // repeated string paths = 1; total_size += 1 * ::google::protobuf::internal::FromIntSize(this->paths_size()); @@ -349,8 +358,10 @@ void FieldMask::Swap(FieldMask* other) { InternalSwap(other); } void FieldMask::InternalSwap(FieldMask* other) { + using std::swap; paths_.InternalSwap(&other->paths_); - std::swap(_cached_size_, other->_cached_size_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata FieldMask::GetMetadata() const { diff --git a/src/google/protobuf/field_mask.pb.h b/src/google/protobuf/field_mask.pb.h index 742c1cf9..4ab0cad0 100644 --- a/src/google/protobuf/field_mask.pb.h +++ b/src/google/protobuf/field_mask.pb.h @@ -48,8 +48,9 @@ struct LIBPROTOBUF_EXPORT TableStruct { static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; static void InitDefaultsImpl(); - static void Shutdown(); }; void LIBPROTOBUF_EXPORT AddDescriptors(); void LIBPROTOBUF_EXPORT InitDefaults(); @@ -68,7 +69,21 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro CopyFrom(from); return *this; } + #if LANG_CXX11 + FieldMask(FieldMask&& from) noexcept + : FieldMask() { + *this = ::std::move(from); + } + inline FieldMask& operator=(FieldMask&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif static const ::google::protobuf::Descriptor* descriptor(); static const FieldMask& default_instance(); @@ -80,6 +95,9 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro 0; void Swap(FieldMask* other); + friend void swap(FieldMask& a, FieldMask& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -157,6 +175,10 @@ class LIBPROTOBUF_EXPORT FieldMask : public ::google::protobuf::Message /* @@pro // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ // FieldMask // repeated string paths = 1; @@ -228,6 +250,9 @@ FieldMask::mutable_paths() { return &paths_; } +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // @@protoc_insertion_point(namespace_scope) diff --git a/src/google/protobuf/generated_message_reflection.cc b/src/google/protobuf/generated_message_reflection.cc index 9aebd901..263d52ab 100644 --- a/src/google/protobuf/generated_message_reflection.cc +++ b/src/google/protobuf/generated_message_reflection.cc @@ -44,7 +44,7 @@ #include <google/protobuf/generated_message_util.h> #include <google/protobuf/map_field.h> #include <google/protobuf/repeated_field.h> -// #include "google/protobuf/bridge/compatibility_mode_support.h" +#include <google/protobuf/wire_format.h> #define GOOGLE_PROTOBUF_HAS_ONEOF @@ -197,32 +197,14 @@ GeneratedMessageReflection::GeneratedMessageReflection( GeneratedMessageReflection::~GeneratedMessageReflection() {} -namespace { -UnknownFieldSet* empty_unknown_field_set_ = NULL; -GOOGLE_PROTOBUF_DECLARE_ONCE(empty_unknown_field_set_once_); - -void DeleteEmptyUnknownFieldSet() { - delete empty_unknown_field_set_; - empty_unknown_field_set_ = NULL; -} - -void InitEmptyUnknownFieldSet() { - empty_unknown_field_set_ = new UnknownFieldSet; - internal::OnShutdown(&DeleteEmptyUnknownFieldSet); -} - -const UnknownFieldSet& GetEmptyUnknownFieldSet() { - ::google::protobuf::GoogleOnceInit(&empty_unknown_field_set_once_, &InitEmptyUnknownFieldSet); - return *empty_unknown_field_set_; -} -} // namespace - const UnknownFieldSet& GeneratedMessageReflection::GetUnknownFields( const Message& message) const { - if (descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO3) { + if (descriptor_->file()->syntax() == FileDescriptor::SYNTAX_PROTO3 && + !GetProto3PreserveUnknownsDefault()) { // We have to ensure that any mutations made to the return value of - // MutableUnknownFields() are not reflected here. - return GetEmptyUnknownFieldSet(); + // MutableUnknownFields() are not reflected here when Proto3 defaults to + // discard unknowns. + return *UnknownFieldSet::default_instance(); } else { return GetInternalMetadataWithArena(message).unknown_fields(); } @@ -1020,7 +1002,7 @@ void GeneratedMessageReflection::ListFields( schema_.HasHasbits() ? GetHasBits(message) : NULL; const uint32* const has_bits_indices = schema_.has_bit_indices_; const uint32* const oneof_case_array = - &GetConstRefAtOffset<uint32>(message, schema_.oneof_case_offset_); + GetConstPointerAtOffset<uint32>(&message, schema_.oneof_case_offset_); output->reserve(descriptor_->field_count()); for (int i = 0; i <= last_non_weak_field_index_; i++) { const FieldDescriptor* field = descriptor_->field(i); @@ -2288,6 +2270,8 @@ class AssignDescriptorsHelper { file_level_enum_descriptors_++; } + const Metadata* GetCurrentMetadataPtr() const { return file_level_metadata_; } + private: MessageFactory* factory_; Metadata* file_level_metadata_; @@ -2297,6 +2281,41 @@ class AssignDescriptorsHelper { const uint32* offsets_; }; +// We have the routines that assign descriptors and build reflection +// automatically delete the allocated reflection. MetadataOwner owns +// all the allocated reflection instances. +struct MetadataOwner { + void AddArray(const Metadata* begin, const Metadata* end) { + MutexLock lock(&mu_); + metadata_arrays_.push_back(std::make_pair(begin, end)); + } + + static MetadataOwner* Instance() { + static MetadataOwner* res = new MetadataOwner; + return res; + } + + private: + // Use the constructor to register the shutdown code. Because c++ makes sure + // this called only once. + MetadataOwner() { OnShutdown(&DeleteMetadata); } + ~MetadataOwner() { + for (int i = 0; i < metadata_arrays_.size(); i++) { + for (const Metadata* m = metadata_arrays_[i].first; + m < metadata_arrays_[i].second; m++) { + delete m->reflection; + } + } + } + + static void DeleteMetadata() { + delete Instance(); + } + + Mutex mu_; + std::vector<std::pair<const Metadata*, const Metadata*> > metadata_arrays_; +}; + } // namespace void AssignDescriptors( @@ -2329,6 +2348,8 @@ void AssignDescriptors( file_level_service_descriptors[i] = file->service(i); } } + MetadataOwner::Instance()->AddArray( + file_level_metadata, helper.GetCurrentMetadataPtr()); } void RegisterAllTypesInternal(const Metadata* file_level_metadata, int size) { @@ -2349,6 +2370,18 @@ void RegisterAllTypes(const Metadata* file_level_metadata, int size) { RegisterAllTypesInternal(file_level_metadata, size); } +void UnknownFieldSetSerializer(const uint8* base, uint32 offset, uint32 tag, + uint32 has_offset, + ::google::protobuf::io::CodedOutputStream* output) { + const void* ptr = base + offset; + const InternalMetadataWithArena* metadata = + static_cast<const InternalMetadataWithArena*>(ptr); + if (metadata->have_unknown_fields()) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + metadata->unknown_fields(), output); + } +} + } // namespace internal } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/generated_message_reflection.h b/src/google/protobuf/generated_message_reflection.h index 12b73ca3..911c3a54 100644 --- a/src/google/protobuf/generated_message_reflection.h +++ b/src/google/protobuf/generated_message_reflection.h @@ -714,6 +714,11 @@ LIBPROTOBUF_EXPORT void AssignDescriptors( LIBPROTOBUF_EXPORT void RegisterAllTypes(const Metadata* file_level_metadata, int size); +// These cannot be in lite so we put them in the reflection. +LIBPROTOBUF_EXPORT void UnknownFieldSetSerializer(const uint8* base, uint32 offset, uint32 tag, + uint32 has_offset, + ::google::protobuf::io::CodedOutputStream* output); + } // namespace internal } // namespace protobuf diff --git a/src/google/protobuf/generated_message_table_driven.cc b/src/google/protobuf/generated_message_table_driven.cc index e281266d..29af1ef6 100644 --- a/src/google/protobuf/generated_message_table_driven.cc +++ b/src/google/protobuf/generated_message_table_driven.cc @@ -32,643 +32,70 @@ #include <google/protobuf/stubs/type_traits.h> +#include <google/protobuf/generated_message_table_driven_lite.h> #include <google/protobuf/io/zero_copy_stream_impl_lite.h> -#include <google/protobuf/metadata_lite.h> +#include <google/protobuf/metadata.h> #include <google/protobuf/repeated_field.h> +#include <google/protobuf/wire_format.h> #include <google/protobuf/wire_format_lite.h> #include <google/protobuf/wire_format_lite_inl.h> - namespace google { namespace protobuf { namespace internal { - namespace { -enum StringType { - StringType_STRING = 0, - StringType_CORD = 1, - StringType_STRING_PIECE = 2 -}; - -template <typename Type> -inline Type* Raw(MessageLite* msg, int64 offset) { - return reinterpret_cast<Type*>(reinterpret_cast<uint8*>(msg) + offset); +UnknownFieldSet* MutableUnknownFields(MessageLite* msg, int64 arena_offset) { + return Raw<InternalMetadataWithArena>(msg, arena_offset) + ->mutable_unknown_fields(); } -template <typename Type> -inline const Type* Raw(const MessageLite* msg, int64 offset) { - return reinterpret_cast<const Type*>(reinterpret_cast<const uint8*>(msg) + - offset); -} +struct UnknownFieldHandler { + static bool Skip(MessageLite* msg, const ParseTable& table, + io::CodedInputStream* input, + int tag) { + GOOGLE_DCHECK(table.unknown_field_set); -inline Arena* GetArena(MessageLite* msg, int64 arena_offset) { - if (GOOGLE_PREDICT_FALSE(arena_offset == -1)) { - return NULL; + return WireFormat::SkipField(input, tag, + MutableUnknownFields(msg, table.arena_offset)); } - return Raw<InternalMetadataWithArenaLite>(msg, arena_offset)->arena(); -} - -template <typename Type> -inline Type* AddField(MessageLite* msg, int64 offset) { -#if LANG_CXX11 - static_assert(std::is_trivially_copy_assignable<Type>::value, - "Do not assign"); -#endif - - google::protobuf::RepeatedField<Type>* repeated = - Raw<google::protobuf::RepeatedField<Type> >(msg, offset); - return repeated->Add(); -} + static void Varint(MessageLite* msg, const ParseTable& table, + int tag, int value) { + GOOGLE_DCHECK(table.unknown_field_set); -template <> -inline string* AddField<string>(MessageLite* msg, int64 offset) { - google::protobuf::RepeatedPtrField<string>* repeated = - Raw<google::protobuf::RepeatedPtrField<string> >(msg, offset); - return repeated->Add(); -} - - -template <typename Type> -inline void AddField(MessageLite* msg, int64 offset, Type value) { -#if LANG_CXX11 - static_assert(std::is_trivially_copy_assignable<Type>::value, - "Do not assign"); -#endif - *AddField<Type>(msg, offset) = value; -} - -inline void SetBit(uint32* has_bits, uint32 has_bit_index) { - GOOGLE_DCHECK(has_bits != NULL); - - uint32 mask = static_cast<uint32>(1u) << (has_bit_index % 32); - has_bits[has_bit_index / 32u] |= mask; -} - -template <typename Type> -inline Type* MutableField(MessageLite* msg, uint32* has_bits, - uint32 has_bit_index, int64 offset) { - SetBit(has_bits, has_bit_index); - return Raw<Type>(msg, offset); -} - -template <typename Type> -inline void SetField(MessageLite* msg, uint32* has_bits, uint32 has_bit_index, - int64 offset, Type value) { -#if LANG_CXX11 - static_assert(std::is_trivially_copy_assignable<Type>::value, - "Do not assign"); -#endif - *MutableField<Type>(msg, has_bits, has_bit_index, offset) = value; -} - -template <bool repeated, bool validate, StringType ctype> -static inline bool HandleString(io::CodedInputStream* input, MessageLite* msg, - Arena* arena, uint32* has_bits, - uint32 has_bit_index, int64 offset, - const void* default_ptr, bool strict_utf8, - const char* field_name) { -#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED - const char* sdata; - size_t size; -#endif - - string* value; - if (repeated) { - value = AddField<string>(msg, offset); - GOOGLE_DCHECK(value != NULL); - } else { - // TODO(ckennelly): Is this optimal? - value = MutableField<ArenaStringPtr>(msg, has_bits, has_bit_index, offset) - ->Mutable(static_cast<const string*>(default_ptr), arena); - GOOGLE_DCHECK(value != NULL); - } + MutableUnknownFields(msg, table.arena_offset)->AddVarint( + WireFormatLite::GetTagFieldNumber(tag), value); + } - if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadString(input, value))) { + static bool ParseExtension( + MessageLite* msg, const ParseTable& table, + io::CodedInputStream* input, int tag) { + ExtensionSet* extensions = GetExtensionSet(msg, table.extension_offset); + if (extensions == NULL) { return false; } -#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED - sdata = value->data(); - size = value->size(); -#endif - -#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED - if (validate) { - if (strict_utf8) { - if (GOOGLE_PREDICT_FALSE(!WireFormatLite::VerifyUtf8String( - sdata, size, WireFormatLite::PARSE, field_name))) { - return false; - } - } else { - WireFormatLite::VerifyUTF8String( - sdata, size, WireFormat::PARSE, field_name); - } - } -#endif - - return true; -} + const Message* prototype = down_cast<const Message*>( + table.default_instance()); -string* MutableUnknownFields(MessageLite* msg, int64 arena_offset) { - return Raw<InternalMetadataWithArenaLite>(msg, arena_offset) - ->mutable_unknown_fields(); -} + GOOGLE_DCHECK(prototype != NULL); + GOOGLE_DCHECK(table.unknown_field_set); + UnknownFieldSet* unknown_fields = + MutableUnknownFields(msg, table.arena_offset); -// RepeatedMessageTypeHandler allows us to operate on RepeatedPtrField fields -// without instantiating the specific template. -class RepeatedMessageTypeHandler { - public: - typedef MessageLite Type; - static Arena* GetArena(Type* t) { return t->GetArena(); } - static void* GetMaybeArenaPointer(Type* t) { - return t->GetMaybeArenaPointer(); - } - static inline Type* NewFromPrototype(const Type* prototype, - Arena* arena = NULL) { - return prototype->New(arena); - } - static void Delete(Type* t, Arena* arena = NULL) { - if (arena == NULL) { - delete t; - } + return extensions->ParseField(tag, input, prototype, unknown_fields); } }; -inline bool ReadGroup(int field_number, io::CodedInputStream* input, - MessageLite* value, const ParseTable& table) { - if (GOOGLE_PREDICT_FALSE(!input->IncrementRecursionDepth())) { - return false; - } - - if (GOOGLE_PREDICT_FALSE(!MergePartialFromCodedStream(value, table, input))) { - return false; - } - - input->DecrementRecursionDepth(); - // Make sure the last thing read was an end tag for this group. - if (GOOGLE_PREDICT_FALSE(!input->LastTagWas(WireFormatLite::MakeTag( - field_number, WireFormatLite::WIRETYPE_END_GROUP)))) { - return false; - } - - return true; -} - -inline bool ReadMessage(io::CodedInputStream* input, MessageLite* value, - const ParseTable& table) { - int length; - if (GOOGLE_PREDICT_FALSE(!input->ReadVarintSizeAsInt(&length))) { - return false; - } - - std::pair<io::CodedInputStream::Limit, int> p = - input->IncrementRecursionDepthAndPushLimit(length); - if (GOOGLE_PREDICT_FALSE(p.second < 0 || - !MergePartialFromCodedStream(value, table, input))) { - return false; - } - - // Make sure that parsing stopped when the limit was hit, not at an endgroup - // tag. - return input->DecrementRecursionDepthAndPopLimit(p.first); -} - } // namespace -class MergePartialFromCodedStreamHelper { - public: - static MessageLite* Add(RepeatedPtrFieldBase* field, - const MessageLite* prototype) { - return field->Add<RepeatedMessageTypeHandler>( - const_cast<MessageLite*>(prototype)); - } -}; - -bool MergePartialFromCodedStream(MessageLite* msg, const ParseTable& table, - io::CodedInputStream* input) { - // We require that has_bits are present, as to avoid having to check for them - // for every field. - // - // TODO(ckennelly): Make this a compile-time parameter with templates. - GOOGLE_DCHECK_GE(table.has_bits_offset, 0); - uint32* has_bits = Raw<uint32>(msg, table.has_bits_offset); - GOOGLE_DCHECK(has_bits != NULL); - - while (true) { - uint32 tag = input->ReadTag(); - - const WireFormatLite::WireType wire_type = - WireFormatLite::GetTagWireType(tag); - const int field_number = WireFormatLite::GetTagFieldNumber(tag); - - if (GOOGLE_PREDICT_FALSE(field_number > table.max_field_number)) { - GOOGLE_DCHECK(!table.unknown_field_set); - ::google::protobuf::io::StringOutputStream unknown_fields_string( - MutableUnknownFields(msg, table.arena_offset)); - ::google::protobuf::io::CodedOutputStream unknown_fields_stream( - &unknown_fields_string, false); - - if (!::google::protobuf::internal::WireFormatLite::SkipField( - input, tag, &unknown_fields_stream)) { - return false; - } - - continue; - } - - // We implicitly verify that data points to a valid field as we check the - // wire types. Entries in table.fields[i] that do not correspond to valid - // field numbers have their normal_wiretype and packed_wiretype fields set - // with the kInvalidMask value. As wire_type cannot take on that value, we - // will never match. - const ParseTableField* data = table.fields + field_number; - - // TODO(ckennelly): Avoid sign extension - const int64 has_bit_index = data->has_bit_index; - const int64 offset = data->offset; - const unsigned char processing_type = data->processing_type; - - if (data->normal_wiretype == static_cast<unsigned char>(wire_type)) { - // TODO(ckennelly): Use a computed goto on GCC/LLVM or otherwise eliminate - // the bounds check on processing_type. - - switch (processing_type) { -#define STR(S) #S -#define HANDLE_TYPE(TYPE, CPPTYPE) \ - case (WireFormatLite::TYPE_##TYPE): { \ - CPPTYPE value; \ - if (GOOGLE_PREDICT_FALSE( \ - (!WireFormatLite::ReadPrimitive< \ - CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, &value)))) { \ - return false; \ - } \ - SetField(msg, has_bits, has_bit_index, offset, value); \ - break; \ - } \ - case (WireFormatLite::TYPE_##TYPE) | kRepeatedMask: { \ - google::protobuf::RepeatedField<CPPTYPE>* values = \ - Raw<google::protobuf::RepeatedField<CPPTYPE> >(msg, offset); \ - if (GOOGLE_PREDICT_FALSE((!WireFormatLite::ReadRepeatedPrimitive< \ - CPPTYPE, WireFormatLite::TYPE_##TYPE>( \ - data->tag_size, tag, input, values)))) { \ - return false; \ - } \ - break; \ - } - - HANDLE_TYPE(INT32, int32) - HANDLE_TYPE(INT64, int64) - HANDLE_TYPE(SINT32, int32) - HANDLE_TYPE(SINT64, int64) - HANDLE_TYPE(UINT32, uint32) - HANDLE_TYPE(UINT64, uint64) - - HANDLE_TYPE(FIXED32, uint32) - HANDLE_TYPE(FIXED64, uint64) - HANDLE_TYPE(SFIXED32, int32) - HANDLE_TYPE(SFIXED64, int64) - - HANDLE_TYPE(FLOAT, float) - HANDLE_TYPE(DOUBLE, double) - - HANDLE_TYPE(BOOL, bool) -#undef HANDLE_TYPE -#undef STR - case WireFormatLite::TYPE_BYTES: -#ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED - case WireFormatLite::TYPE_STRING: -#endif - { - GOOGLE_DCHECK(!table.unknown_field_set); - Arena* const arena = GetArena(msg, table.arena_offset); - const void* default_ptr = table.aux[field_number].strings.default_ptr; - - if (GOOGLE_PREDICT_FALSE((!HandleString<false, false, StringType_STRING>( - input, msg, arena, has_bits, has_bit_index, offset, - default_ptr, false, NULL)))) { - return false; - } - break; - } - case (WireFormatLite::TYPE_BYTES) | kRepeatedMask: -#ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED - case (WireFormatLite::TYPE_STRING) | kRepeatedMask: -#endif - { - GOOGLE_DCHECK(!table.unknown_field_set); - Arena* const arena = GetArena(msg, table.arena_offset); - const void* default_ptr = - table.aux[field_number].strings.default_ptr; - - if (GOOGLE_PREDICT_FALSE((!HandleString<true, false, StringType_STRING>( - input, msg, arena, has_bits, has_bit_index, offset, - default_ptr, false, NULL)))) { - return false; - } - break; - } -#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED - case (WireFormatLite::TYPE_STRING): { - GOOGLE_DCHECK(!table.unknown_field_set); - Arena* const arena = GetArena(msg, table.arena_offset); - const void* default_ptr = table.aux[field_number].strings.default_ptr; - const char* field_name = table.aux[field_number].strings.field_name; - const bool strict_utf8 = table.aux[field_number].strings.strict_utf8; - - if (GOOGLE_PREDICT_FALSE((!HandleString<false, true, StringType_STRING>( - input, msg, arena, has_bits, has_bit_index, offset, - default_ptr, strict_utf8, field_name)))) { - return false; - } - break; - } - case (WireFormatLite::TYPE_STRING) | kRepeatedMask: { - GOOGLE_DCHECK(!table.unknown_field_set); - Arena* const arena = GetArena(msg, table.arena_offset); - const void* default_ptr = table.aux[field_number].strings.default_ptr; - const char* field_name = table.aux[field_number].strings.field_name; - const bool strict_utf8 = table.aux[field_number].strings.strict_utf8; - - if (GOOGLE_PREDICT_FALSE((!HandleString<true, true, StringType_STRING>( - input, msg, arena, has_bits, has_bit_index, offset, - default_ptr, strict_utf8, field_name)))) { - return false; - } - break; - } -#endif - case WireFormatLite::TYPE_ENUM: { - int value; - if (GOOGLE_PREDICT_FALSE((!WireFormatLite::ReadPrimitive< - int, WireFormatLite::TYPE_ENUM>(input, &value)))) { - return false; - } - - AuxillaryParseTableField::EnumValidator validator = - table.aux[field_number].enums.validator; - if (validator(value)) { - SetField(msg, has_bits, has_bit_index, offset, value); - } else { - GOOGLE_DCHECK(!table.unknown_field_set); - - ::google::protobuf::io::StringOutputStream unknown_fields_string( - MutableUnknownFields(msg, table.arena_offset)); - ::google::protobuf::io::CodedOutputStream unknown_fields_stream( - &unknown_fields_string, false); - unknown_fields_stream.WriteVarint32(tag); - unknown_fields_stream.WriteVarint32(value); - } - break; - } - case WireFormatLite::TYPE_ENUM | kRepeatedMask: { - int value; - if (GOOGLE_PREDICT_FALSE((!WireFormatLite::ReadPrimitive< - int, WireFormatLite::TYPE_ENUM>(input, &value)))) { - return false; - } - - AuxillaryParseTableField::EnumValidator validator = - table.aux[field_number].enums.validator; - if (validator(value)) { - AddField(msg, offset, value); - } else { - GOOGLE_DCHECK(!table.unknown_field_set); - - ::google::protobuf::io::StringOutputStream unknown_fields_string( - MutableUnknownFields(msg, table.arena_offset)); - ::google::protobuf::io::CodedOutputStream unknown_fields_stream( - &unknown_fields_string, false); - unknown_fields_stream.WriteVarint32(tag); - unknown_fields_stream.WriteVarint32(value); - } - - break; - } - case WireFormatLite::TYPE_GROUP: { - MessageLite** submsg_holder = - MutableField<MessageLite*>(msg, has_bits, has_bit_index, offset); - MessageLite* submsg = *submsg_holder; - - if (submsg == NULL) { - GOOGLE_DCHECK(!table.unknown_field_set); - Arena* const arena = GetArena(msg, table.arena_offset); - const MessageLite* prototype = - table.aux[field_number].messages.default_message(); - submsg = prototype->New(arena); - *submsg_holder = submsg; - } - - const ParseTable* ptable = - table.aux[field_number].messages.parse_table; - - if (ptable) { - if (GOOGLE_PREDICT_FALSE( - !ReadGroup(field_number, input, submsg, *ptable))) { - return false; - } - } else if (!WireFormatLite::ReadGroup(field_number, input, submsg)) { - return false; - } - - break; - } - case WireFormatLite::TYPE_GROUP | kRepeatedMask: { - RepeatedPtrFieldBase* field = Raw<RepeatedPtrFieldBase>(msg, offset); - const MessageLite* prototype = - table.aux[field_number].messages.default_message(); - GOOGLE_DCHECK(prototype != NULL); - - MessageLite* submsg = - MergePartialFromCodedStreamHelper::Add(field, prototype); - const ParseTable* ptable = - table.aux[field_number].messages.parse_table; - - if (ptable) { - if (GOOGLE_PREDICT_FALSE( - !ReadGroup(field_number, input, submsg, *ptable))) { - return false; - } - } else if (!WireFormatLite::ReadGroup(field_number, input, submsg)) { - return false; - } - - break; - } - case WireFormatLite::TYPE_MESSAGE: { - MessageLite** submsg_holder = - MutableField<MessageLite*>(msg, has_bits, has_bit_index, offset); - MessageLite* submsg = *submsg_holder; - - if (submsg == NULL) { - GOOGLE_DCHECK(!table.unknown_field_set); - Arena* const arena = GetArena(msg, table.arena_offset); - const MessageLite* prototype = - table.aux[field_number].messages.default_message(); - submsg = prototype->New(arena); - *submsg_holder = submsg; - } - - const ParseTable* ptable = - table.aux[field_number].messages.parse_table; - - if (ptable) { - if (GOOGLE_PREDICT_FALSE(!ReadMessage(input, submsg, *ptable))) { - return false; - } - } else if (!WireFormatLite::ReadMessage(input, submsg)) { - return false; - } - - break; - } - // TODO(ckennelly): Adapt ReadMessageNoVirtualNoRecursionDepth and - // manage input->IncrementRecursionDepth() here. - case WireFormatLite::TYPE_MESSAGE | kRepeatedMask: { - RepeatedPtrFieldBase* field = Raw<RepeatedPtrFieldBase>(msg, offset); - const MessageLite* prototype = - table.aux[field_number].messages.default_message(); - GOOGLE_DCHECK(prototype != NULL); - - MessageLite* submsg = - MergePartialFromCodedStreamHelper::Add(field, prototype); - const ParseTable* ptable = - table.aux[field_number].messages.parse_table; - - if (ptable) { - if (GOOGLE_PREDICT_FALSE(!ReadMessage(input, submsg, *ptable))) { - return false; - } - } else if (!WireFormatLite::ReadMessage(input, submsg)) { - return false; - } - - break; - } - case 0: { - // Done. - return true; - } - default: - break; - } - } else if (data->packed_wiretype == static_cast<unsigned char>(wire_type)) { - // Non-packable fields have their packed_wiretype masked with - // kNotPackedMask, which is impossible to match here. - GOOGLE_DCHECK(processing_type & kRepeatedMask); - GOOGLE_DCHECK_NE(processing_type, kRepeatedMask); - - - - // TODO(ckennelly): Use a computed goto on GCC/LLVM. - // - // Mask out kRepeatedMask bit, allowing the jump table to be smaller. - switch (static_cast<WireFormatLite::FieldType>( - processing_type ^ kRepeatedMask)) { -#define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, CPPTYPE_METHOD) \ - case WireFormatLite::TYPE_##TYPE: { \ - google::protobuf::RepeatedField<CPPTYPE>* values = \ - Raw<google::protobuf::RepeatedField<CPPTYPE> >(msg, offset); \ - if (GOOGLE_PREDICT_FALSE( \ - (!WireFormatLite::ReadPackedPrimitive< \ - CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, values)))) { \ - return false; \ - } \ - break; \ - } - - HANDLE_PACKED_TYPE(INT32, int32, Int32) - HANDLE_PACKED_TYPE(INT64, int64, Int64) - HANDLE_PACKED_TYPE(SINT32, int32, Int32) - HANDLE_PACKED_TYPE(SINT64, int64, Int64) - HANDLE_PACKED_TYPE(UINT32, uint32, UInt32) - HANDLE_PACKED_TYPE(UINT64, uint64, UInt64) - - HANDLE_PACKED_TYPE(FIXED32, uint32, UInt32) - HANDLE_PACKED_TYPE(FIXED64, uint64, UInt64) - HANDLE_PACKED_TYPE(SFIXED32, int32, Int32) - HANDLE_PACKED_TYPE(SFIXED64, int64, Int64) - - HANDLE_PACKED_TYPE(FLOAT, float, Float) - HANDLE_PACKED_TYPE(DOUBLE, double, Double) - - HANDLE_PACKED_TYPE(BOOL, bool, Bool) -#undef HANDLE_PACKED_TYPE - case WireFormatLite::TYPE_ENUM: { - // To avoid unnecessarily calling MutableUnknownFields (which mutates - // InternalMetadataWithArena) when all inputs in the repeated series - // are valid, we implement our own parser rather than call - // WireFormat::ReadPackedEnumPreserveUnknowns. - uint32 length; - if (GOOGLE_PREDICT_FALSE(!input->ReadVarint32(&length))) { - return false; - } - - AuxillaryParseTableField::EnumValidator validator = - table.aux[field_number].enums.validator; - google::protobuf::RepeatedField<int>* values = - Raw<google::protobuf::RepeatedField<int> >(msg, offset); - string* unknown_fields = NULL; - - io::CodedInputStream::Limit limit = input->PushLimit(length); - while (input->BytesUntilLimit() > 0) { - int value; - if (GOOGLE_PREDICT_FALSE( - (!google::protobuf::internal::WireFormatLite::ReadPrimitive< - int, WireFormatLite::TYPE_ENUM>(input, &value)))) { - return false; - } - - if (validator(value)) { - values->Add(value); - } else { - if (GOOGLE_PREDICT_FALSE(unknown_fields == NULL)) { - GOOGLE_DCHECK(!table.unknown_field_set); - unknown_fields = MutableUnknownFields(msg, table.arena_offset); - } - - ::google::protobuf::io::StringOutputStream unknown_fields_string( - unknown_fields); - ::google::protobuf::io::CodedOutputStream unknown_fields_stream( - &unknown_fields_string, false); - unknown_fields_stream.WriteVarint32(tag); - unknown_fields_stream.WriteVarint32(value); - } - } - input->PopLimit(limit); - - break; - } - case WireFormatLite::TYPE_STRING: - case WireFormatLite::TYPE_GROUP: - case WireFormatLite::TYPE_MESSAGE: - case WireFormatLite::TYPE_BYTES: - GOOGLE_DCHECK(false); - return false; - default: - break; - } - } else { - if (wire_type == WireFormatLite::WIRETYPE_END_GROUP) { - // Must be the end of the message. - return true; - } - - // process unknown field. - GOOGLE_DCHECK(!table.unknown_field_set); - ::google::protobuf::io::StringOutputStream unknown_fields_string( - MutableUnknownFields(msg, table.arena_offset)); - ::google::protobuf::io::CodedOutputStream unknown_fields_stream( - &unknown_fields_string, false); - - if (!::google::protobuf::internal::WireFormatLite::SkipField( - input, tag, &unknown_fields_stream)) { - return false; - } - } - } +bool MergePartialFromCodedStream( + MessageLite* msg, const ParseTable& table, io::CodedInputStream* input) { + return MergePartialFromCodedStreamImpl<UnknownFieldHandler, + InternalMetadataWithArena>(msg, table, + input); } } // namespace internal diff --git a/src/google/protobuf/generated_message_table_driven.h b/src/google/protobuf/generated_message_table_driven.h index 557c57d3..5eb63dbd 100644 --- a/src/google/protobuf/generated_message_table_driven.h +++ b/src/google/protobuf/generated_message_table_driven.h @@ -31,7 +31,11 @@ #ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_H__ #define GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_H__ +#include <google/protobuf/map.h> +#include <google/protobuf/map_entry_lite.h> #include <google/protobuf/message_lite.h> +#include <google/protobuf/wire_format_lite.h> +#include <google/protobuf/wire_format_lite_inl.h> #if LANG_CXX11 #define PROTOBUF_CONSTEXPR constexpr @@ -54,10 +58,14 @@ namespace google { namespace protobuf { namespace internal { +// Processing-type masks. static PROTOBUF_CONSTEXPR const unsigned char kOneofMask = 0x40; static PROTOBUF_CONSTEXPR const unsigned char kRepeatedMask = 0x20; -// Check this against types. +// Mask for the raw type: either a WireFormatLite::FieldType or one of the +// ProcessingTypes below, without the oneof or repeated flag. +static PROTOBUF_CONSTEXPR const unsigned char kTypeMask = 0x1f; +// Wire type masks. static PROTOBUF_CONSTEXPR const unsigned char kNotPackedMask = 0x10; static PROTOBUF_CONSTEXPR const unsigned char kInvalidMask = 0x20; @@ -66,10 +74,11 @@ enum ProcessingTypes { TYPE_STRING_STRING_PIECE = 20, TYPE_BYTES_CORD = 21, TYPE_BYTES_STRING_PIECE = 22, + TYPE_MAP = 23, }; #if LANG_CXX11 -static_assert(TYPE_BYTES_STRING_PIECE < kRepeatedMask, "Invalid enum"); +static_assert(TYPE_MAP < kRepeatedMask, "Invalid enum"); #endif // TODO(ckennelly): Add a static assertion to ensure that these masks do not @@ -81,7 +90,9 @@ static_assert(TYPE_BYTES_STRING_PIECE < kRepeatedMask, "Invalid enum"); // AuxillaryParseTableField. struct ParseTableField { uint32 offset; - uint32 has_bit_index; + // The presence_index ordinarily represents a has_bit index, but for fields + // inside a oneof it represents the index in _oneof_case_. + uint32 presence_index; unsigned char normal_wiretype; unsigned char packed_wiretype; @@ -100,7 +111,6 @@ union AuxillaryParseTableField { // Enums struct enum_aux { EnumValidator validator; - const char* name; }; enum_aux enums; // Group, messages @@ -119,11 +129,14 @@ union AuxillaryParseTableField { struct string_aux { const void* default_ptr; const char* field_name; - bool strict_utf8; - const char* name; }; string_aux strings; + struct map_aux { + bool (*parse_map)(io::CodedInputStream*, void*); + }; + map_aux maps; + #if LANG_CXX11 AuxillaryParseTableField() = default; #else @@ -135,6 +148,9 @@ union AuxillaryParseTableField { AuxillaryParseTableField::message_aux m) : messages(m) {} PROTOBUF_CONSTEXPR AuxillaryParseTableField( AuxillaryParseTableField::string_aux s) : strings(s) {} + PROTOBUF_CONSTEXPR AuxillaryParseTableField( + AuxillaryParseTableField::map_aux m) + : maps(m) {} }; struct ParseTable { @@ -145,8 +161,19 @@ struct ParseTable { // TODO(ckennelly): Vet these for sign extension. int64 has_bits_offset; + int64 oneof_case_offset; + int64 extension_offset; int64 arena_offset; - int unknown_field_set; + + // ExplicitlyInitialized<T> -> T requires a reinterpret_cast, which prevents + // the tables from being constructed as a constexpr. We use void to avoid + // the cast. + const void* default_instance_void; + const MessageLite* default_instance() const { + return static_cast<const MessageLite*>(default_instance_void); + } + + bool unknown_field_set; }; // TODO(jhen): Remove the __NVCC__ check when we get a version of nvcc that @@ -163,8 +190,39 @@ static_assert(std::is_pod<AuxillaryParseTableField::string_aux>::value, ""); static_assert(std::is_pod<ParseTable>::value, ""); #endif +// TODO(ckennelly): Consolidate these implementations into a single one, using +// dynamic dispatch to the appropriate unknown field handler. bool MergePartialFromCodedStream(MessageLite* msg, const ParseTable& table, io::CodedInputStream* input); +bool MergePartialFromCodedStreamLite(MessageLite* msg, const ParseTable& table, + io::CodedInputStream* input); + +template <typename MEntry> +struct MapEntryToMapField; + +template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType, + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +struct MapEntryToMapField<MapEntryLite<Key, Value, kKeyFieldType, + kValueFieldType, default_enum_value> > { + typedef MapFieldLite<MapEntryLite<Key, Value, kKeyFieldType, kValueFieldType, + default_enum_value>, + Key, Value, kKeyFieldType, kValueFieldType, + default_enum_value> + MapFieldType; +}; + +template <typename Entry> +bool ParseMap(io::CodedInputStream* input, void* map_field) { + typedef typename MapEntryToMapField<Entry>::MapFieldType MapFieldType; + typedef google::protobuf::Map<typename Entry::EntryKeyType, + typename Entry::EntryValueType> + MapType; + typedef typename Entry::template Parser<MapFieldType, MapType> ParserType; + + ParserType parser(static_cast<MapFieldType*>(map_field)); + return ::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual(input, + &parser); +} } // namespace internal } // namespace protobuf diff --git a/src/google/protobuf/generated_message_table_driven_lite.cc b/src/google/protobuf/generated_message_table_driven_lite.cc new file mode 100644 index 00000000..90a50505 --- /dev/null +++ b/src/google/protobuf/generated_message_table_driven_lite.cc @@ -0,0 +1,109 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#include <google/protobuf/generated_message_table_driven_lite.h> + +#include <google/protobuf/stubs/type_traits.h> + +#include <google/protobuf/io/zero_copy_stream_impl_lite.h> +#include <google/protobuf/metadata_lite.h> +#include <google/protobuf/repeated_field.h> +#include <google/protobuf/wire_format_lite.h> +#include <google/protobuf/wire_format_lite_inl.h> + +namespace google { +namespace protobuf { +namespace internal { + +namespace { + +string* MutableUnknownFields(MessageLite* msg, int64 arena_offset) { + return Raw<InternalMetadataWithArenaLite>(msg, arena_offset) + ->mutable_unknown_fields(); +} + +struct UnknownFieldHandlerLite { + static bool Skip(MessageLite* msg, const ParseTable& table, + io::CodedInputStream* input, + int tag) { + GOOGLE_DCHECK(!table.unknown_field_set); + ::google::protobuf::io::StringOutputStream unknown_fields_string( + MutableUnknownFields(msg, table.arena_offset)); + ::google::protobuf::io::CodedOutputStream unknown_fields_stream( + &unknown_fields_string, false); + + return ::google::protobuf::internal::WireFormatLite::SkipField( + input, tag, &unknown_fields_stream); + } + + static void Varint(MessageLite* msg, const ParseTable& table, + int tag, int value) { + GOOGLE_DCHECK(!table.unknown_field_set); + + ::google::protobuf::io::StringOutputStream unknown_fields_string( + MutableUnknownFields(msg, table.arena_offset)); + ::google::protobuf::io::CodedOutputStream unknown_fields_stream( + &unknown_fields_string, false); + unknown_fields_stream.WriteVarint32(tag); + unknown_fields_stream.WriteVarint32(value); + } + + static bool ParseExtension( + MessageLite* msg, const ParseTable& table, + io::CodedInputStream* input, int tag) { + ExtensionSet* extensions = GetExtensionSet(msg, table.extension_offset); + if (extensions == NULL) { + return false; + } + + const MessageLite* prototype = table.default_instance(); + + GOOGLE_DCHECK(!table.unknown_field_set); + ::google::protobuf::io::StringOutputStream unknown_fields_string( + MutableUnknownFields(msg, table.arena_offset)); + ::google::protobuf::io::CodedOutputStream unknown_fields_stream( + &unknown_fields_string, false); + return extensions->ParseField( + tag, input, prototype, &unknown_fields_stream); + } +}; + +} // namespace + +bool MergePartialFromCodedStreamLite( + MessageLite* msg, const ParseTable& table, io::CodedInputStream* input) { + return MergePartialFromCodedStreamImpl<UnknownFieldHandlerLite, + InternalMetadataWithArenaLite>( + msg, table, input); +} + +} // namespace internal +} // namespace protobuf +} // namespace google diff --git a/src/google/protobuf/generated_message_table_driven_lite.h b/src/google/protobuf/generated_message_table_driven_lite.h new file mode 100644 index 00000000..20b4da21 --- /dev/null +++ b/src/google/protobuf/generated_message_table_driven_lite.h @@ -0,0 +1,823 @@ +// Protocol Buffers - Google's data interchange format +// Copyright 2008 Google Inc. All rights reserved. +// https://developers.google.com/protocol-buffers/ +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +#ifndef GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_LITE_H__ +#define GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_LITE_H__ + +#include <google/protobuf/generated_message_table_driven.h> + +#include <google/protobuf/stubs/type_traits.h> + +#include <google/protobuf/io/zero_copy_stream_impl_lite.h> +#include <google/protobuf/extension_set.h> +#include <google/protobuf/metadata_lite.h> +#include <google/protobuf/repeated_field.h> +#include <google/protobuf/wire_format_lite.h> +#include <google/protobuf/wire_format_lite_inl.h> + + +namespace google { +namespace protobuf { +namespace internal { + + +enum StringType { + StringType_STRING = 0, + StringType_CORD = 1, + StringType_STRING_PIECE = 2 +}; + +// Logically a superset of StringType, consisting of all field types that +// require special initialization. +enum ProcessingType { + ProcessingType_STRING = 0, + ProcessingType_CORD = 1, + ProcessingType_STRING_PIECE = 2, + ProcessingType_MESSAGE = 3 +}; + +enum Cardinality { + Cardinality_SINGULAR = 0, + Cardinality_REPEATED = 1, + Cardinality_ONEOF = 3 +}; + +template <typename Type> +inline Type* Raw(MessageLite* msg, int64 offset) { + return reinterpret_cast<Type*>(reinterpret_cast<uint8*>(msg) + offset); +} + +template <typename Type> +inline const Type* Raw(const MessageLite* msg, int64 offset) { + return reinterpret_cast<const Type*>(reinterpret_cast<const uint8*>(msg) + + offset); +} + +template <typename InternalMetadata> +inline Arena* GetArena(MessageLite* msg, int64 arena_offset) { + if (GOOGLE_PREDICT_FALSE(arena_offset == -1)) { + return NULL; + } + + return Raw<InternalMetadata>(msg, arena_offset)->arena(); +} + +inline ExtensionSet* GetExtensionSet(MessageLite* msg, int64 extension_offset) { + if (extension_offset == -1) { + return NULL; + } + + return Raw<ExtensionSet>(msg, extension_offset); +} + +template <typename Type> +inline Type* AddField(MessageLite* msg, int64 offset) { +#if LANG_CXX11 + static_assert(has_trivial_copy<Type>::value, + "Do not assign"); +#endif + + google::protobuf::RepeatedField<Type>* repeated = + Raw<google::protobuf::RepeatedField<Type> >(msg, offset); + return repeated->Add(); +} + +template <> +inline string* AddField<string>(MessageLite* msg, int64 offset) { + google::protobuf::RepeatedPtrField<string>* repeated = + Raw<google::protobuf::RepeatedPtrField<string> >(msg, offset); + return repeated->Add(); +} + + +template <typename Type> +inline void AddField(MessageLite* msg, int64 offset, Type value) { +#if LANG_CXX11 + static_assert(has_trivial_copy<Type>::value, + "Do not assign"); +#endif + *AddField<Type>(msg, offset) = value; +} + +inline void SetBit(uint32* has_bits, uint32 has_bit_index) { + GOOGLE_DCHECK(has_bits != NULL); + + uint32 mask = static_cast<uint32>(1u) << (has_bit_index % 32); + has_bits[has_bit_index / 32u] |= mask; +} + +template <typename Type> +inline Type* MutableField(MessageLite* msg, uint32* has_bits, + uint32 has_bit_index, int64 offset) { + SetBit(has_bits, has_bit_index); + return Raw<Type>(msg, offset); +} + +template <typename Type> +inline void SetField(MessageLite* msg, uint32* has_bits, uint32 has_bit_index, + int64 offset, Type value) { +#if LANG_CXX11 + static_assert(has_trivial_copy<Type>::value, + "Do not assign"); +#endif + *MutableField<Type>(msg, has_bits, has_bit_index, offset) = value; +} + +template <typename Type> +inline void SetOneofField(MessageLite* msg, uint32* oneof_case, + uint32 oneof_case_index, int64 offset, + int field_number, Type value) { + oneof_case[oneof_case_index] = field_number; + *Raw<Type>(msg, offset) = value; +} + +// Clears a oneof field. The field argument should correspond to the particular +// field that is currently set in the oneof. +inline void ClearOneofField(const ParseTableField& field, Arena* arena, + MessageLite* msg) { + switch (field.processing_type & kTypeMask) { + case WireFormatLite::TYPE_MESSAGE: + if (arena == NULL) { + delete *Raw<MessageLite*>(msg, field.offset); + } + break; + + case WireFormatLite::TYPE_STRING: + case WireFormatLite::TYPE_BYTES: + Raw<ArenaStringPtr>(msg, field.offset) + ->Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); + break; + + default: + // No cleanup needed. + break; + } +} + +// Clears and reinitializes a oneof field as necessary, in preparation for +// parsing a new value with type field_type and field number field_number. +// +// Note: the oneof_case argument should point directly to the _oneof_case_ +// element corresponding to this particular oneof, not to the beginning of the +// _oneof_case_ array. +template <ProcessingType field_type> +inline void ResetOneofField(const ParseTable& table, int field_number, + Arena* arena, MessageLite* msg, uint32* oneof_case, + int64 offset, const void* default_ptr) { + if (*oneof_case == field_number) { + // The oneof is already set to the right type, so there is no need to clear + // it. + return; + } + + if (*oneof_case != 0) { + ClearOneofField(table.fields[*oneof_case], arena, msg); + } + *oneof_case = field_number; + + switch (field_type) { + case ProcessingType_STRING: + Raw<ArenaStringPtr>(msg, offset) + ->UnsafeSetDefault(static_cast<const string*>(default_ptr)); + break; + case ProcessingType_MESSAGE: + MessageLite** submessage = Raw<MessageLite*>(msg, offset); + const MessageLite* prototype = + table.aux[field_number].messages.default_message(); + *submessage = prototype->New(arena); + break; + } +} + +template <Cardinality cardinality, bool validate, StringType ctype> +static inline bool HandleString(io::CodedInputStream* input, MessageLite* msg, + Arena* arena, uint32* has_bits, + uint32 has_bit_index, int64 offset, + const void* default_ptr, + const char* field_name) { +#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + const char* sdata; + size_t size; +#endif + + string* value; + switch (cardinality) { + case Cardinality_SINGULAR: + // TODO(ckennelly): Is this optimal? + value = + MutableField<ArenaStringPtr>(msg, has_bits, has_bit_index, offset) + ->Mutable(static_cast<const string*>(default_ptr), arena); + break; + case Cardinality_REPEATED: + value = AddField<string>(msg, offset); + break; + case Cardinality_ONEOF: + value = Raw<ArenaStringPtr>(msg, offset) + ->Mutable(static_cast<const string*>(default_ptr), arena); + break; + } + GOOGLE_DCHECK(value != NULL); + + if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadString(input, value))) { + return false; + } + +#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + sdata = value->data(); + size = value->size(); +#endif + +#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + if (validate) { + WireFormatLite::VerifyUtf8String(sdata, size, WireFormatLite::PARSE, + field_name); + } +#endif + + return true; +} + +template <typename UnknownFieldHandler, typename InternalMetadata, + Cardinality cardinality> +inline bool HandleEnum(const ParseTable& table, io::CodedInputStream* input, + MessageLite* msg, uint32* presence, + uint32 presence_index, int64 offset, uint32 tag, + int field_number) { + int value; + if (GOOGLE_PREDICT_FALSE( + (!WireFormatLite::ReadPrimitive<int, WireFormatLite::TYPE_ENUM>( + input, &value)))) { + return false; + } + + AuxillaryParseTableField::EnumValidator validator = + table.aux[field_number].enums.validator; + if (validator(value)) { + switch (cardinality) { + case Cardinality_SINGULAR: + SetField(msg, presence, presence_index, offset, value); + break; + case Cardinality_REPEATED: + AddField(msg, offset, value); + break; + case Cardinality_ONEOF: + ClearOneofField(table.fields[presence[presence_index]], + GetArena<InternalMetadata>(msg, table.arena_offset), + msg); + SetOneofField(msg, presence, presence_index, offset, field_number, + value); + break; + } + } else { + UnknownFieldHandler::Varint(msg, table, tag, value); + } + + return true; +} + +// RepeatedMessageTypeHandler allows us to operate on RepeatedPtrField fields +// without instantiating the specific template. +class RepeatedMessageTypeHandler { + public: + typedef MessageLite Type; + static Arena* GetArena(Type* t) { return t->GetArena(); } + static void* GetMaybeArenaPointer(Type* t) { + return t->GetMaybeArenaPointer(); + } + static inline Type* NewFromPrototype(const Type* prototype, + Arena* arena = NULL) { + return prototype->New(arena); + } + static void Delete(Type* t, Arena* arena = NULL) { + if (arena == NULL) { + delete t; + } + } +}; + +inline bool ReadGroup(int field_number, io::CodedInputStream* input, + MessageLite* value) { + if (GOOGLE_PREDICT_FALSE(!input->IncrementRecursionDepth())) { + return false; + } + + if (GOOGLE_PREDICT_FALSE(!value->MergePartialFromCodedStream(input))) { + return false; + } + + input->DecrementRecursionDepth(); + // Make sure the last thing read was an end tag for this group. + if (GOOGLE_PREDICT_FALSE(!input->LastTagWas(WireFormatLite::MakeTag( + field_number, WireFormatLite::WIRETYPE_END_GROUP)))) { + return false; + } + + return true; +} + +inline bool ReadMessage(io::CodedInputStream* input, MessageLite* value) { + int length; + if (GOOGLE_PREDICT_FALSE(!input->ReadVarintSizeAsInt(&length))) { + return false; + } + + std::pair<io::CodedInputStream::Limit, int> p = + input->IncrementRecursionDepthAndPushLimit(length); + if (GOOGLE_PREDICT_FALSE(p.second < 0 || + !value->MergePartialFromCodedStream(input))) { + return false; + } + + // Make sure that parsing stopped when the limit was hit, not at an endgroup + // tag. + return input->DecrementRecursionDepthAndPopLimit(p.first); +} + +class MergePartialFromCodedStreamHelper { + public: + static MessageLite* Add(RepeatedPtrFieldBase* field, + const MessageLite* prototype) { + return field->Add<RepeatedMessageTypeHandler>( + const_cast<MessageLite*>(prototype)); + } +}; + +template <typename UnknownFieldHandler, typename InternalMetadata> +bool MergePartialFromCodedStreamImpl(MessageLite* msg, const ParseTable& table, + io::CodedInputStream* input) { + // We require that has_bits are present, as to avoid having to check for them + // for every field. + // + // TODO(ckennelly): Make this a compile-time parameter with templates. + GOOGLE_DCHECK_GE(table.has_bits_offset, 0); + uint32* has_bits = Raw<uint32>(msg, table.has_bits_offset); + GOOGLE_DCHECK(has_bits != NULL); + + while (true) { + uint32 tag = input->ReadTag(); + + const WireFormatLite::WireType wire_type = + WireFormatLite::GetTagWireType(tag); + const int field_number = WireFormatLite::GetTagFieldNumber(tag); + + if (field_number > table.max_field_number) { + // check for possible extensions + if (UnknownFieldHandler::ParseExtension(msg, table, input, tag)) { + // successfully parsed + continue; + } + + if (GOOGLE_PREDICT_FALSE(!UnknownFieldHandler::Skip(msg, table, input, tag))) { + return false; + } + + continue; + } + + // We implicitly verify that data points to a valid field as we check the + // wire types. Entries in table.fields[i] that do not correspond to valid + // field numbers have their normal_wiretype and packed_wiretype fields set + // with the kInvalidMask value. As wire_type cannot take on that value, we + // will never match. + const ParseTableField* data = table.fields + field_number; + + // TODO(ckennelly): Avoid sign extension + const int64 presence_index = data->presence_index; + const int64 offset = data->offset; + const unsigned char processing_type = data->processing_type; + + if (data->normal_wiretype == static_cast<unsigned char>(wire_type)) { + // TODO(ckennelly): Use a computed goto on GCC/LLVM or otherwise eliminate + // the bounds check on processing_type. + + switch (processing_type) { +#define HANDLE_TYPE(TYPE, CPPTYPE) \ + case (WireFormatLite::TYPE_##TYPE): { \ + CPPTYPE value; \ + if (GOOGLE_PREDICT_FALSE( \ + (!WireFormatLite::ReadPrimitive< \ + CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, &value)))) { \ + return false; \ + } \ + SetField(msg, has_bits, presence_index, offset, value); \ + break; \ + } \ + case (WireFormatLite::TYPE_##TYPE) | kRepeatedMask: { \ + google::protobuf::RepeatedField<CPPTYPE>* values = \ + Raw<google::protobuf::RepeatedField<CPPTYPE> >(msg, offset); \ + if (GOOGLE_PREDICT_FALSE((!WireFormatLite::ReadRepeatedPrimitive< \ + CPPTYPE, WireFormatLite::TYPE_##TYPE>( \ + data->tag_size, tag, input, values)))) { \ + return false; \ + } \ + break; \ + } \ + case (WireFormatLite::TYPE_##TYPE) | kOneofMask: { \ + uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset); \ + CPPTYPE value; \ + if (GOOGLE_PREDICT_FALSE( \ + (!WireFormatLite::ReadPrimitive< \ + CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, &value)))) { \ + return false; \ + } \ + ClearOneofField(table.fields[oneof_case[presence_index]], \ + GetArena<InternalMetadata>(msg, table.arena_offset), msg); \ + SetOneofField(msg, oneof_case, presence_index, offset, field_number, \ + value); \ + break; \ + } + + HANDLE_TYPE(INT32, int32) + HANDLE_TYPE(INT64, int64) + HANDLE_TYPE(SINT32, int32) + HANDLE_TYPE(SINT64, int64) + HANDLE_TYPE(UINT32, uint32) + HANDLE_TYPE(UINT64, uint64) + + HANDLE_TYPE(FIXED32, uint32) + HANDLE_TYPE(FIXED64, uint64) + HANDLE_TYPE(SFIXED32, int32) + HANDLE_TYPE(SFIXED64, int64) + + HANDLE_TYPE(FLOAT, float) + HANDLE_TYPE(DOUBLE, double) + + HANDLE_TYPE(BOOL, bool) +#undef HANDLE_TYPE + case WireFormatLite::TYPE_BYTES: +#ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + case WireFormatLite::TYPE_STRING: +#endif + { + Arena* const arena = + GetArena<InternalMetadata>(msg, table.arena_offset); + const void* default_ptr = table.aux[field_number].strings.default_ptr; + + if (GOOGLE_PREDICT_FALSE(( + !HandleString<Cardinality_SINGULAR, false, StringType_STRING>( + input, msg, arena, has_bits, presence_index, offset, + default_ptr, NULL)))) { + return false; + } + break; + } + case WireFormatLite::TYPE_BYTES | kOneofMask: +#ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + case WireFormatLite::TYPE_STRING | kOneofMask: +#endif + { + Arena* const arena = + GetArena<InternalMetadata>(msg, table.arena_offset); + uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset); + const void* default_ptr = table.aux[field_number].strings.default_ptr; + + ResetOneofField<ProcessingType_STRING>( + table, field_number, arena, msg, oneof_case + presence_index, + offset, default_ptr); + + if (GOOGLE_PREDICT_FALSE( + (!HandleString<Cardinality_ONEOF, false, StringType_STRING>( + input, msg, arena, has_bits, presence_index, offset, + default_ptr, NULL)))) { + return false; + } + break; + } + case (WireFormatLite::TYPE_BYTES) | kRepeatedMask: +#ifndef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + case (WireFormatLite::TYPE_STRING) | kRepeatedMask: +#endif + { + Arena* const arena = + GetArena<InternalMetadata>(msg, table.arena_offset); + const void* default_ptr = + table.aux[field_number].strings.default_ptr; + + if (GOOGLE_PREDICT_FALSE(( + !HandleString<Cardinality_REPEATED, false, StringType_STRING>( + input, msg, arena, has_bits, presence_index, offset, + default_ptr, NULL)))) { + return false; + } + break; + } +#ifdef GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED + case (WireFormatLite::TYPE_STRING): { + Arena* const arena = + GetArena<InternalMetadata>(msg, table.arena_offset); + const void* default_ptr = table.aux[field_number].strings.default_ptr; + const char* field_name = table.aux[field_number].strings.field_name; + + if (GOOGLE_PREDICT_FALSE( + (!HandleString<Cardinality_SINGULAR, true, StringType_STRING>( + input, msg, arena, has_bits, presence_index, offset, + default_ptr, field_name)))) { + return false; + } + break; + } + case (WireFormatLite::TYPE_STRING) | kRepeatedMask: { + Arena* const arena = + GetArena<InternalMetadata>(msg, table.arena_offset); + const void* default_ptr = table.aux[field_number].strings.default_ptr; + const char* field_name = table.aux[field_number].strings.field_name; + + if (GOOGLE_PREDICT_FALSE( + (!HandleString<Cardinality_REPEATED, true, StringType_STRING>( + input, msg, arena, has_bits, presence_index, offset, + default_ptr, field_name)))) { + return false; + } + break; + } + case (WireFormatLite::TYPE_STRING) | kOneofMask: { + Arena* const arena = + GetArena<InternalMetadata>(msg, table.arena_offset); + uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset); + const void* default_ptr = table.aux[field_number].strings.default_ptr; + const char* field_name = table.aux[field_number].strings.field_name; + + ResetOneofField<ProcessingType_STRING>( + table, field_number, arena, msg, oneof_case + presence_index, + offset, default_ptr); + + if (GOOGLE_PREDICT_FALSE( + (!HandleString<Cardinality_ONEOF, true, StringType_STRING>( + input, msg, arena, has_bits, presence_index, offset, + default_ptr, field_name)))) { + return false; + } + break; + } +#endif + case WireFormatLite::TYPE_ENUM: { + if (GOOGLE_PREDICT_FALSE((!HandleEnum<UnknownFieldHandler, InternalMetadata, + Cardinality_SINGULAR>( + table, input, msg, has_bits, presence_index, offset, tag, + field_number)))) { + return false; + } + break; + } + case WireFormatLite::TYPE_ENUM | kRepeatedMask: { + if (GOOGLE_PREDICT_FALSE((!HandleEnum<UnknownFieldHandler, InternalMetadata, + Cardinality_REPEATED>( + table, input, msg, has_bits, presence_index, offset, tag, + field_number)))) { + return false; + } + break; + } + case WireFormatLite::TYPE_ENUM | kOneofMask: { + uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset); + if (GOOGLE_PREDICT_FALSE((!HandleEnum<UnknownFieldHandler, InternalMetadata, + Cardinality_ONEOF>( + table, input, msg, oneof_case, presence_index, offset, tag, + field_number)))) { + return false; + } + break; + } + case WireFormatLite::TYPE_GROUP: { + MessageLite** submsg_holder = + MutableField<MessageLite*>(msg, has_bits, presence_index, offset); + MessageLite* submsg = *submsg_holder; + + if (submsg == NULL) { + Arena* const arena = + GetArena<InternalMetadata>(msg, table.arena_offset); + const MessageLite* prototype = + table.aux[field_number].messages.default_message(); + submsg = prototype->New(arena); + *submsg_holder = submsg; + } + + if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadGroup( + field_number, input, submsg))) { + return false; + } + + break; + } + case WireFormatLite::TYPE_GROUP | kRepeatedMask: { + RepeatedPtrFieldBase* field = Raw<RepeatedPtrFieldBase>(msg, offset); + const MessageLite* prototype = + table.aux[field_number].messages.default_message(); + GOOGLE_DCHECK(prototype != NULL); + + MessageLite* submsg = + MergePartialFromCodedStreamHelper::Add(field, prototype); + + if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadGroup( + field_number, input, submsg))) { + return false; + } + + break; + } + case WireFormatLite::TYPE_MESSAGE: { + MessageLite** submsg_holder = + MutableField<MessageLite*>(msg, has_bits, presence_index, offset); + MessageLite* submsg = *submsg_holder; + + if (submsg == NULL) { + Arena* const arena = + GetArena<InternalMetadata>(msg, table.arena_offset); + const MessageLite* prototype = + table.aux[field_number].messages.default_message(); + submsg = prototype->New(arena); + *submsg_holder = submsg; + } + + if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadMessage(input, submsg))) { + return false; + } + + break; + } + // TODO(ckennelly): Adapt ReadMessageNoVirtualNoRecursionDepth and + // manage input->IncrementRecursionDepth() here. + case WireFormatLite::TYPE_MESSAGE | kRepeatedMask: { + RepeatedPtrFieldBase* field = Raw<RepeatedPtrFieldBase>(msg, offset); + const MessageLite* prototype = + table.aux[field_number].messages.default_message(); + GOOGLE_DCHECK(prototype != NULL); + + MessageLite* submsg = + MergePartialFromCodedStreamHelper::Add(field, prototype); + + if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadMessage(input, submsg))) { + return false; + } + + break; + } + case WireFormatLite::TYPE_MESSAGE | kOneofMask: { + Arena* const arena = + GetArena<InternalMetadata>(msg, table.arena_offset); + uint32* oneof_case = Raw<uint32>(msg, table.oneof_case_offset); + MessageLite** submsg_holder = Raw<MessageLite*>(msg, offset); + ResetOneofField<ProcessingType_MESSAGE>( + table, field_number, arena, msg, oneof_case + presence_index, + offset, NULL); + MessageLite* submsg = *submsg_holder; + + if (GOOGLE_PREDICT_FALSE(!WireFormatLite::ReadMessage(input, submsg))) { + return false; + } + + break; + } + case TYPE_MAP: { + if (GOOGLE_PREDICT_FALSE(!(*table.aux[field_number].maps.parse_map)( + input, Raw<void>(msg, offset)))) { + return false; + } + break; + } + case 0: { + // Done. + return true; + } + default: + break; + } + } else if (data->packed_wiretype == static_cast<unsigned char>(wire_type)) { + // Non-packable fields have their packed_wiretype masked with + // kNotPackedMask, which is impossible to match here. + GOOGLE_DCHECK(processing_type & kRepeatedMask); + GOOGLE_DCHECK_NE(processing_type, kRepeatedMask); + GOOGLE_DCHECK_EQ(0, processing_type & kOneofMask); + + + + // TODO(ckennelly): Use a computed goto on GCC/LLVM. + // + // Mask out kRepeatedMask bit, allowing the jump table to be smaller. + switch (static_cast<WireFormatLite::FieldType>( + processing_type ^ kRepeatedMask)) { +#define HANDLE_PACKED_TYPE(TYPE, CPPTYPE, CPPTYPE_METHOD) \ + case WireFormatLite::TYPE_##TYPE: { \ + google::protobuf::RepeatedField<CPPTYPE>* values = \ + Raw<google::protobuf::RepeatedField<CPPTYPE> >(msg, offset); \ + if (GOOGLE_PREDICT_FALSE( \ + (!WireFormatLite::ReadPackedPrimitive< \ + CPPTYPE, WireFormatLite::TYPE_##TYPE>(input, values)))) { \ + return false; \ + } \ + break; \ + } + + HANDLE_PACKED_TYPE(INT32, int32, Int32) + HANDLE_PACKED_TYPE(INT64, int64, Int64) + HANDLE_PACKED_TYPE(SINT32, int32, Int32) + HANDLE_PACKED_TYPE(SINT64, int64, Int64) + HANDLE_PACKED_TYPE(UINT32, uint32, UInt32) + HANDLE_PACKED_TYPE(UINT64, uint64, UInt64) + + HANDLE_PACKED_TYPE(FIXED32, uint32, UInt32) + HANDLE_PACKED_TYPE(FIXED64, uint64, UInt64) + HANDLE_PACKED_TYPE(SFIXED32, int32, Int32) + HANDLE_PACKED_TYPE(SFIXED64, int64, Int64) + + HANDLE_PACKED_TYPE(FLOAT, float, Float) + HANDLE_PACKED_TYPE(DOUBLE, double, Double) + + HANDLE_PACKED_TYPE(BOOL, bool, Bool) +#undef HANDLE_PACKED_TYPE + case WireFormatLite::TYPE_ENUM: { + // To avoid unnecessarily calling MutableUnknownFields (which mutates + // InternalMetadataWithArena) when all inputs in the repeated series + // are valid, we implement our own parser rather than call + // WireFormat::ReadPackedEnumPreserveUnknowns. + uint32 length; + if (GOOGLE_PREDICT_FALSE(!input->ReadVarint32(&length))) { + return false; + } + + AuxillaryParseTableField::EnumValidator validator = + table.aux[field_number].enums.validator; + google::protobuf::RepeatedField<int>* values = + Raw<google::protobuf::RepeatedField<int> >(msg, offset); + + io::CodedInputStream::Limit limit = input->PushLimit(length); + while (input->BytesUntilLimit() > 0) { + int value; + if (GOOGLE_PREDICT_FALSE( + (!google::protobuf::internal::WireFormatLite::ReadPrimitive< + int, WireFormatLite::TYPE_ENUM>(input, &value)))) { + return false; + } + + if (validator(value)) { + values->Add(value); + } else { + // TODO(ckennelly): Consider caching here. + UnknownFieldHandler::Varint(msg, table, tag, value); + } + } + input->PopLimit(limit); + + break; + } + case WireFormatLite::TYPE_STRING: + case WireFormatLite::TYPE_GROUP: + case WireFormatLite::TYPE_MESSAGE: + case WireFormatLite::TYPE_BYTES: + GOOGLE_DCHECK(false); + return false; + default: + break; + } + } else { + if (wire_type == WireFormatLite::WIRETYPE_END_GROUP) { + // Must be the end of the message. + return true; + } + + // check for possible extensions + if (UnknownFieldHandler::ParseExtension(msg, table, input, tag)) { + // successfully parsed + continue; + } + + // process unknown field. + if (GOOGLE_PREDICT_FALSE(!UnknownFieldHandler::Skip(msg, table, input, tag))) { + return false; + } + } + } +} + +} // namespace internal +} // namespace protobuf + +} // namespace google +#endif // GOOGLE_PROTOBUF_GENERATED_MESSAGE_TABLE_DRIVEN_LITE_H__ diff --git a/src/google/protobuf/generated_message_util.cc b/src/google/protobuf/generated_message_util.cc index 35d8156e..c9dfe61a 100644 --- a/src/google/protobuf/generated_message_util.cc +++ b/src/google/protobuf/generated_message_util.cc @@ -35,7 +35,17 @@ #include <google/protobuf/generated_message_util.h> #include <limits> +#include <vector> +#include <google/protobuf/io/coded_stream_inl.h> +#include <google/protobuf/io/coded_stream.h> +#include <google/protobuf/arenastring.h> +#include <google/protobuf/extension_set.h> +#include <google/protobuf/message_lite.h> +#include <google/protobuf/metadata_lite.h> +#include <google/protobuf/repeated_field.h> +#include <google/protobuf/wire_format_lite.h> +#include <google/protobuf/wire_format_lite_inl.h> namespace google { namespace protobuf { @@ -51,7 +61,7 @@ double NaN() { ExplicitlyConstructed< ::std::string> fixed_address_empty_string; GOOGLE_PROTOBUF_DECLARE_ONCE(empty_string_once_init_); -void DeleteEmptyString() { fixed_address_empty_string.Shutdown(); } +void DeleteEmptyString() { fixed_address_empty_string.Destruct(); } void InitEmptyString() { fixed_address_empty_string.DefaultConstruct(); @@ -75,6 +85,616 @@ void InitProtobufDefaults() { GetEmptyString(); } +template <typename T> +const T& Get(const void* ptr) { + return *static_cast<const T*>(ptr); +} + +// PrimitiveTypeHelper is a wrapper around the interface of WireFormatLite. +// WireFormatLite has a very inconvenient interface with respect to template +// meta-programming. This class wraps the different named functions into +// a single Serialize / SerializeToArray interface. +template <int type> +struct PrimitiveTypeHelper; + +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_BOOL> { + typedef bool Type; + static void Serialize(const void* ptr, + ::google::protobuf::io::CodedOutputStream* output) { + WireFormatLite::WriteBoolNoTag(Get<bool>(ptr), output); + } + static uint8* SerializeToArray(const void* ptr, uint8* buffer) { + return WireFormatLite::WriteBoolNoTagToArray(Get<Type>(ptr), buffer); + } +}; + +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_INT32> { + typedef int32 Type; + static void Serialize(const void* ptr, + ::google::protobuf::io::CodedOutputStream* output) { + WireFormatLite::WriteInt32NoTag(Get<int32>(ptr), output); + } + static uint8* SerializeToArray(const void* ptr, uint8* buffer) { + return WireFormatLite::WriteInt32NoTagToArray(Get<Type>(ptr), buffer); + } +}; + +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_SINT32> { + typedef int32 Type; + static void Serialize(const void* ptr, + ::google::protobuf::io::CodedOutputStream* output) { + WireFormatLite::WriteSInt32NoTag(Get<int32>(ptr), output); + } + static uint8* SerializeToArray(const void* ptr, uint8* buffer) { + return WireFormatLite::WriteSInt32NoTagToArray(Get<Type>(ptr), buffer); + } +}; + +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_UINT32> { + typedef uint32 Type; + static void Serialize(const void* ptr, + ::google::protobuf::io::CodedOutputStream* output) { + WireFormatLite::WriteUInt32NoTag(Get<uint32>(ptr), output); + } + static uint8* SerializeToArray(const void* ptr, uint8* buffer) { + return WireFormatLite::WriteUInt32NoTagToArray(Get<Type>(ptr), buffer); + } +}; +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_INT64> { + typedef int64 Type; + static void Serialize(const void* ptr, + ::google::protobuf::io::CodedOutputStream* output) { + WireFormatLite::WriteInt64NoTag(Get<int64>(ptr), output); + } + static uint8* SerializeToArray(const void* ptr, uint8* buffer) { + return WireFormatLite::WriteInt64NoTagToArray(Get<Type>(ptr), buffer); + } +}; + +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_SINT64> { + typedef int64 Type; + static void Serialize(const void* ptr, + ::google::protobuf::io::CodedOutputStream* output) { + WireFormatLite::WriteSInt64NoTag(Get<int64>(ptr), output); + } + static uint8* SerializeToArray(const void* ptr, uint8* buffer) { + return WireFormatLite::WriteSInt64NoTagToArray(Get<Type>(ptr), buffer); + } +}; +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_UINT64> { + typedef uint64 Type; + static void Serialize(const void* ptr, + ::google::protobuf::io::CodedOutputStream* output) { + WireFormatLite::WriteUInt64NoTag(Get<uint64>(ptr), output); + } + static uint8* SerializeToArray(const void* ptr, uint8* buffer) { + return WireFormatLite::WriteUInt64NoTagToArray(Get<Type>(ptr), buffer); + } +}; + +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_FIXED32> { + typedef uint32 Type; + static void Serialize(const void* ptr, + ::google::protobuf::io::CodedOutputStream* output) { + WireFormatLite::WriteFixed32NoTag(Get<uint32>(ptr), output); + } + static uint8* SerializeToArray(const void* ptr, uint8* buffer) { + return WireFormatLite::WriteFixed32NoTagToArray(Get<Type>(ptr), buffer); + } +}; + +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_FIXED64> { + typedef uint64 Type; + static void Serialize(const void* ptr, + ::google::protobuf::io::CodedOutputStream* output) { + WireFormatLite::WriteFixed64NoTag(Get<uint64>(ptr), output); + } + static uint8* SerializeToArray(const void* ptr, uint8* buffer) { + return WireFormatLite::WriteFixed64NoTagToArray(Get<Type>(ptr), buffer); + } +}; + +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_ENUM> + : PrimitiveTypeHelper<WireFormatLite::TYPE_INT32> {}; + +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_SFIXED32> + : PrimitiveTypeHelper<WireFormatLite::TYPE_FIXED32> { + typedef int32 Type; +}; +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_SFIXED64> + : PrimitiveTypeHelper<WireFormatLite::TYPE_FIXED64> { + typedef int64 Type; +}; +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_FLOAT> + : PrimitiveTypeHelper<WireFormatLite::TYPE_FIXED32> { + typedef float Type; +}; +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_DOUBLE> + : PrimitiveTypeHelper<WireFormatLite::TYPE_FIXED64> { + typedef double Type; +}; + +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_STRING> { + typedef string Type; + static void Serialize(const void* ptr, + ::google::protobuf::io::CodedOutputStream* output) { + const Type& value = *static_cast<const Type*>(ptr); + output->WriteVarint32(value.size()); + output->WriteRawMaybeAliased(value.data(), value.size()); + } + static uint8* SerializeToArray(const void* ptr, uint8* buffer) { + const Type& value = *static_cast<const Type*>(ptr); + return io::CodedOutputStream::WriteStringWithSizeToArray(value, buffer); + } +}; + +template <> +struct PrimitiveTypeHelper<WireFormatLite::TYPE_BYTES> + : PrimitiveTypeHelper<WireFormatLite::TYPE_STRING> {}; + + +// We want to serialize to both CodedOutputStream and directly into byte arrays +// without duplicating the code. In fact we might want extra output channels in +// the future. +template <typename O, int type> +struct OutputHelper; + +template <int type, typename O> +void SerializeTo(const void* ptr, O* output) { + OutputHelper<O, type>::Serialize(ptr, output); +} + +template <typename O> +void WriteTagTo(uint32 tag, O* output) { + SerializeTo<WireFormatLite::TYPE_UINT32>(&tag, output); +} + +template <typename O> +void WriteLengthTo(uint32 length, O* output) { + SerializeTo<WireFormatLite::TYPE_UINT32>(&length, output); +} + +// Specialization for coded output stream +template <int type> +struct OutputHelper< ::google::protobuf::io::CodedOutputStream, type> { + static void Serialize(const void* ptr, + ::google::protobuf::io::CodedOutputStream* output) { + PrimitiveTypeHelper<type>::Serialize(ptr, output); + } +}; + +// Specialization for writing into a plain array +struct ArrayOutput { + uint8* ptr; + bool is_deterministic; +}; + +template <int type> +struct OutputHelper<ArrayOutput, type> { + static void Serialize(const void* ptr, ArrayOutput* output) { + output->ptr = PrimitiveTypeHelper<type>::SerializeToArray(ptr, output->ptr); + } +}; + +void SerializeMessageNoTable(const MessageLite* msg, + ::google::protobuf::io::CodedOutputStream* output) { + msg->SerializeWithCachedSizes(output); +} + +void SerializeMessageNoTable(const MessageLite* msg, ArrayOutput* output) { + output->ptr = msg->InternalSerializeWithCachedSizesToArray( + output->is_deterministic, output->ptr); +} + +// Helper to branch to fast path if possible +void SerializeMessageDispatch(const ::google::protobuf::MessageLite& msg, + const FieldMetadata* field_table, int num_fields, + int32 cached_size, + ::google::protobuf::io::CodedOutputStream* output) { + const uint8* base = reinterpret_cast<const uint8*>(&msg); + // Try the fast path + uint8* ptr = output->GetDirectBufferForNBytesAndAdvance(cached_size); + if (ptr) { + // We use virtual dispatch to enable dedicated generated code for the + // fast path. + msg.InternalSerializeWithCachedSizesToArray( + output->IsSerializationDeterministic(), ptr); + return; + } + SerializeInternal(base, field_table, num_fields, output); +} + +// Helper to branch to fast path if possible +void SerializeMessageDispatch(const ::google::protobuf::MessageLite& msg, + const FieldMetadata* field_table, int num_fields, + int32 cached_size, ArrayOutput* output) { + const uint8* base = reinterpret_cast<const uint8*>(&msg); + output->ptr = SerializeInternalToArray(base, field_table, num_fields, + output->is_deterministic, output->ptr); +} + +// Serializing messages is special as it's not a primitive type and needs an +// explicit overload for each output type. +template <typename O> +void SerializeMessageTo(const MessageLite* msg, const void* table_ptr, + O* output) { + const SerializationTable* table = + static_cast<const SerializationTable*>(table_ptr); + if (!table) { + // Proto1 + WriteLengthTo(msg->GetCachedSize(), output); + SerializeMessageNoTable(msg, output); + return; + } + const FieldMetadata* field_table = table->field_table; + const uint8* base = reinterpret_cast<const uint8*>(msg); + int cached_size = *reinterpret_cast<const int32*>(base + field_table->offset); + WriteLengthTo(cached_size, output); + int num_fields = table->num_fields - 1; + SerializeMessageDispatch(*msg, field_table + 1, num_fields, cached_size, + output); +} + +// Almost the same as above only it doesn't output the length field. +template <typename O> +void SerializeGroupTo(const MessageLite* msg, const void* table_ptr, + O* output) { + const SerializationTable* table = + static_cast<const SerializationTable*>(table_ptr); + if (!table) { + // Proto1 + SerializeMessageNoTable(msg, output); + return; + } + const FieldMetadata* field_table = table->field_table; + const uint8* base = reinterpret_cast<const uint8*>(msg); + int cached_size = *reinterpret_cast<const int32*>(base + field_table->offset); + int num_fields = table->num_fields - 1; + SerializeMessageDispatch(*msg, field_table + 1, num_fields, cached_size, + output); +} + +template <int type> +struct SingularFieldHelper { + template <typename O> + static void Serialize(const void* field, const FieldMetadata& md, O* output) { + WriteTagTo(md.tag, output); + SerializeTo<type>(field, output); + } +}; + +template <> +struct SingularFieldHelper<WireFormatLite::TYPE_STRING> { + template <typename O> + static void Serialize(const void* field, const FieldMetadata& md, O* output) { + WriteTagTo(md.tag, output); + SerializeTo<WireFormatLite::TYPE_STRING>(&Get<ArenaStringPtr>(field).Get(), + output); + } +}; + +template <> +struct SingularFieldHelper<WireFormatLite::TYPE_BYTES> + : SingularFieldHelper<WireFormatLite::TYPE_STRING> {}; + +template <> +struct SingularFieldHelper<WireFormatLite::TYPE_GROUP> { + template <typename O> + static void Serialize(const void* field, const FieldMetadata& md, O* output) { + WriteTagTo(md.tag, output); + SerializeGroupTo(Get<const MessageLite*>(field), + static_cast<const SerializationTable*>(md.ptr), output); + WriteTagTo(md.tag + 1, output); + } +}; + +template <> +struct SingularFieldHelper<WireFormatLite::TYPE_MESSAGE> { + template <typename O> + static void Serialize(const void* field, const FieldMetadata& md, O* output) { + WriteTagTo(md.tag, output); + SerializeMessageTo(Get<const MessageLite*>(field), + static_cast<const SerializationTable*>(md.ptr), output); + } +}; + +template <int type> +struct RepeatedFieldHelper { + template <typename O> + static void Serialize(const void* field, const FieldMetadata& md, O* output) { + typedef typename PrimitiveTypeHelper<type>::Type T; + const RepeatedField<T>& array = Get<RepeatedField<T> >(field); + for (int i = 0; i < array.size(); i++) { + WriteTagTo(md.tag, output); + SerializeTo<type>(&array[i], output); + } + } +}; + +// We need to use a helper class to get access to the private members +class AccessorHelper { + public: + static int Size(const RepeatedPtrFieldBase& x) { return x.size(); } + static void const* Get(const RepeatedPtrFieldBase& x, int idx) { + return x.raw_data()[idx]; + } +}; + +template <> +struct RepeatedFieldHelper<WireFormatLite::TYPE_STRING> { + template <typename O> + static void Serialize(const void* field, const FieldMetadata& md, O* output) { + const internal::RepeatedPtrFieldBase& array = + Get<internal::RepeatedPtrFieldBase>(field); + for (int i = 0; i < AccessorHelper::Size(array); i++) { + WriteTagTo(md.tag, output); + SerializeTo<WireFormatLite::TYPE_STRING>(AccessorHelper::Get(array, i), + output); + } + } +}; + +template <> +struct RepeatedFieldHelper<WireFormatLite::TYPE_BYTES> + : RepeatedFieldHelper<WireFormatLite::TYPE_STRING> {}; + +template <> +struct RepeatedFieldHelper<WireFormatLite::TYPE_GROUP> { + template <typename O> + static void Serialize(const void* field, const FieldMetadata& md, O* output) { + const internal::RepeatedPtrFieldBase& array = + Get<internal::RepeatedPtrFieldBase>(field); + for (int i = 0; i < AccessorHelper::Size(array); i++) { + WriteTagTo(md.tag, output); + SerializeGroupTo( + static_cast<const MessageLite*>(AccessorHelper::Get(array, i)), + static_cast<const SerializationTable*>(md.ptr), output); + WriteTagTo(md.tag + 1, output); + } + } +}; + +template <> +struct RepeatedFieldHelper<WireFormatLite::TYPE_MESSAGE> { + template <typename O> + static void Serialize(const void* field, const FieldMetadata& md, O* output) { + const internal::RepeatedPtrFieldBase& array = + Get<internal::RepeatedPtrFieldBase>(field); + for (int i = 0; i < AccessorHelper::Size(array); i++) { + WriteTagTo(md.tag, output); + SerializeMessageTo( + static_cast<const MessageLite*>(AccessorHelper::Get(array, i)), md.ptr, + output); + } + } +}; + + +template <int type> +struct PackedFieldHelper { + template <typename O> + static void Serialize(const void* field, const FieldMetadata& md, O* output) { + typedef typename PrimitiveTypeHelper<type>::Type T; + const RepeatedField<T>& array = Get<RepeatedField<T> >(field); + if (array.empty()) return; + WriteTagTo(md.tag, output); + int cached_size = + Get<int>(static_cast<const uint8*>(field) + sizeof(RepeatedField<T>)); + WriteLengthTo(cached_size, output); + for (int i = 0; i < array.size(); i++) { + SerializeTo<type>(&array[i], output); + } + } +}; + +template <> +struct PackedFieldHelper<WireFormatLite::TYPE_STRING> { + template <typename O> + static void Serialize(const void* field, const FieldMetadata& md, O* output) { + GOOGLE_LOG(FATAL) << "Not implemented field number " << md.tag << " with type " + << md.type; + } +}; + +template <> +struct PackedFieldHelper<WireFormatLite::TYPE_BYTES> + : PackedFieldHelper<WireFormatLite::TYPE_STRING> {}; +template <> +struct PackedFieldHelper<WireFormatLite::TYPE_GROUP> + : PackedFieldHelper<WireFormatLite::TYPE_STRING> {}; +template <> +struct PackedFieldHelper<WireFormatLite::TYPE_MESSAGE> + : PackedFieldHelper<WireFormatLite::TYPE_STRING> {}; + +template <int type> +struct OneOfFieldHelper { + template <typename O> + static void Serialize(const void* field, const FieldMetadata& md, O* output) { + SingularFieldHelper<type>::Serialize(field, md, output); + } +}; + + +void SerializeNotImplemented(int field) { + GOOGLE_LOG(FATAL) << "Not implemented field number " << field; +} + +// When switching to c++11 we should make these constexpr functions +#define SERIALIZE_TABLE_OP(type, type_class) \ + ((type - 1) + static_cast<int>(type_class) * FieldMetadata::kNumTypes) + +int FieldMetadata::CalculateType(int type, + FieldMetadata::FieldTypeClass type_class) { + return SERIALIZE_TABLE_OP(type, type_class); +} + +template <int type> +bool IsNull(const void* ptr) { + return *static_cast<const typename PrimitiveTypeHelper<type>::Type*>(ptr) == + 0; +} + +template <> +bool IsNull<WireFormatLite::TYPE_STRING>(const void* ptr) { + return static_cast<const ArenaStringPtr*>(ptr)->Get().size() == 0; +} + +template <> +bool IsNull<WireFormatLite::TYPE_BYTES>(const void* ptr) { + return static_cast<const ArenaStringPtr*>(ptr)->Get().size() == 0; +} + +template <> +bool IsNull<WireFormatLite::TYPE_GROUP>(const void* ptr) { + return Get<const MessageLite*>(ptr) == NULL; +} + +template <> +bool IsNull<WireFormatLite::TYPE_MESSAGE>(const void* ptr) { + return Get<const MessageLite*>(ptr) == NULL; +} + + +#define SERIALIZERS_FOR_TYPE(type) \ + case SERIALIZE_TABLE_OP(type, FieldMetadata::kPresence): \ + if (!IsPresent(base, field_metadata.has_offset)) continue; \ + SingularFieldHelper<type>::Serialize(ptr, field_metadata, output); \ + break; \ + case SERIALIZE_TABLE_OP(type, FieldMetadata::kNoPresence): \ + if (IsNull<type>(ptr)) continue; \ + SingularFieldHelper<type>::Serialize(ptr, field_metadata, output); \ + break; \ + case SERIALIZE_TABLE_OP(type, FieldMetadata::kRepeated): \ + RepeatedFieldHelper<type>::Serialize(ptr, field_metadata, output); \ + break; \ + case SERIALIZE_TABLE_OP(type, FieldMetadata::kPacked): \ + PackedFieldHelper<type>::Serialize(ptr, field_metadata, output); \ + break; \ + case SERIALIZE_TABLE_OP(type, FieldMetadata::kOneOf): \ + if (!IsOneofPresent(base, field_metadata.has_offset, field_metadata.tag)) \ + continue; \ + OneOfFieldHelper<type>::Serialize(ptr, field_metadata, output); \ + break + +void SerializeInternal(const uint8* base, + const FieldMetadata* field_metadata_table, + int32 num_fields, + ::google::protobuf::io::CodedOutputStream* output) { + for (int i = 0; i < num_fields; i++) { + const FieldMetadata& field_metadata = field_metadata_table[i]; + const uint8* ptr = base + field_metadata.offset; + switch (field_metadata.type) { + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_DOUBLE); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_FLOAT); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_INT64); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_UINT64); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_INT32); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_FIXED64); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_FIXED32); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_BOOL); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_STRING); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_GROUP); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_MESSAGE); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_BYTES); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_UINT32); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_ENUM); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SFIXED32); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SFIXED64); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SINT32); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SINT64); + + // Special cases + case FieldMetadata::kSpecial: + reinterpret_cast<SpecialSerializer>( + const_cast<void*>(field_metadata.ptr))( + base, field_metadata.offset, field_metadata.tag, + field_metadata.has_offset, output); + break; + default: + // __builtin_unreachable() + SerializeNotImplemented(field_metadata.type); + } + } +} + +uint8* SerializeInternalToArray(const uint8* base, + const FieldMetadata* field_metadata_table, + int32 num_fields, bool is_deterministic, + uint8* buffer) { + ArrayOutput array_output = {buffer, is_deterministic}; + ArrayOutput* output = &array_output; + for (int i = 0; i < num_fields; i++) { + const FieldMetadata& field_metadata = field_metadata_table[i]; + const uint8* ptr = base + field_metadata.offset; + switch (field_metadata.type) { + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_DOUBLE); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_FLOAT); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_INT64); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_UINT64); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_INT32); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_FIXED64); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_FIXED32); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_BOOL); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_STRING); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_GROUP); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_MESSAGE); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_BYTES); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_UINT32); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_ENUM); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SFIXED32); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SFIXED64); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SINT32); + SERIALIZERS_FOR_TYPE(WireFormatLite::TYPE_SINT64); + // Special cases + case FieldMetadata::kSpecial: { + io::ArrayOutputStream array_stream(array_output.ptr, INT_MAX); + io::CodedOutputStream output(&array_stream); + output.SetSerializationDeterministic(is_deterministic); + reinterpret_cast<SpecialSerializer>( + const_cast<void*>(field_metadata.ptr))( + base, field_metadata.offset, field_metadata.tag, + field_metadata.has_offset, &output); + array_output.ptr += output.ByteCount(); + } break; + default: + // __builtin_unreachable() + SerializeNotImplemented(field_metadata.type); + } + } + return array_output.ptr; +} +#undef SERIALIZERS_FOR_TYPE + +void ExtensionSerializer(const uint8* ptr, uint32 offset, uint32 tag, + uint32 has_offset, + ::google::protobuf::io::CodedOutputStream* output) { + reinterpret_cast<const ExtensionSet*>(ptr + offset) + ->SerializeWithCachedSizes(tag, has_offset, output); +} + +void UnknownFieldSerializerLite(const uint8* ptr, uint32 offset, uint32 tag, + uint32 has_offset, + ::google::protobuf::io::CodedOutputStream* output) { + output->WriteString( + reinterpret_cast<const InternalMetadataWithArenaLite*>(ptr + offset) + ->unknown_fields()); +} + } // namespace internal } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/generated_message_util.h b/src/google/protobuf/generated_message_util.h index 44174466..71165dc1 100644 --- a/src/google/protobuf/generated_message_util.h +++ b/src/google/protobuf/generated_message_util.h @@ -41,25 +41,22 @@ #include <assert.h> #include <climits> #include <string> +#include <vector> #include <google/protobuf/stubs/logging.h> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/once.h> #include <google/protobuf/has_bits.h> - -#ifndef PROTOBUF_FINAL -#if LANG_CXX11 && !defined(__NVCC__) -#define PROTOBUF_FINAL final -#else -#define PROTOBUF_FINAL -#endif -#endif // !PROTOBUF_FINAL +#include <google/protobuf/map_entry_lite.h> +#include <google/protobuf/message_lite.h> +#include <google/protobuf/wire_format_lite.h> namespace google { namespace protobuf { class Arena; + namespace io { class CodedInputStream; } namespace internal { @@ -106,80 +103,10 @@ namespace internal { reinterpret_cast<const char*>(16)) #endif -#define GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(ONEOF, FIELD) \ - static_cast< ::google::protobuf::uint32>( \ - reinterpret_cast<const char*>(&(ONEOF->FIELD)) \ - - reinterpret_cast<const char*>(ONEOF)) -// TODO(acozzette): remove this transitional macro after updating generated code -#define PROTO2_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(ONEOF, FIELD) \ - GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET(ONEOF, FIELD) - // Constants for special floating point values. LIBPROTOBUF_EXPORT double Infinity(); LIBPROTOBUF_EXPORT double NaN(); -// This type is used to define a global variable, without it's constructor -// and destructor run on start and end of the program lifetime. This circumvents -// the initial construction order fiasco, while keeping the address of the -// empty string a compile time constant. -template <typename T> -class ExplicitlyConstructed { - public: - void DefaultConstruct() { - new (&union_) T(); - init_ = true; - } - - bool IsInitialized() { return init_; } - void Shutdown() { - if (init_) { - init_ = false; - get_mutable()->~T(); - } - } - -#if LANG_CXX11 - constexpr -#endif - const T& - get() const { - return reinterpret_cast<const T&>(union_); - } - T* get_mutable() { return reinterpret_cast<T*>(&union_); } - - private: - // Prefer c++14 aligned_storage, but for compatibility this will do. - union AlignedUnion { - char space[sizeof(T)]; - int64 align_to_int64; - void* align_to_ptr; - } union_; - bool init_; // false by linker -}; - -// TODO(jieluo): Change to template. We have tried to use template, -// but it causes net/rpc/python:rpcutil_test fail (the empty string will -// init twice). It may related to swig. Change to template after we -// found the solution. - -// Default empty string object. Don't use this directly. Instead, call -// GetEmptyString() to get the reference. -extern ExplicitlyConstructed< ::std::string> fixed_address_empty_string; -LIBPROTOBUF_EXPORT extern ProtobufOnceType empty_string_once_init_; -LIBPROTOBUF_EXPORT void InitEmptyString(); - - -LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyStringAlreadyInited() { - return fixed_address_empty_string.get(); -} - -LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyString() { - ::google::protobuf::GoogleOnceInit(&empty_string_once_init_, &InitEmptyString); - return GetEmptyStringAlreadyInited(); -} - -LIBPROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const string& str); - // True if IsInitialized() is true for all elements of t. Type is expected // to be a RepeatedPtrField<some message type>. It's useful to have this @@ -195,32 +122,156 @@ template <class Type> bool AllAreInitialized(const Type& t) { LIBPROTOBUF_EXPORT void InitProtobufDefaults(); -// We compute sizes as size_t but cache them as int. This function converts a -// computed size to a cached size. Since we don't proceed with serialization if -// the total size was > INT_MAX, it is not important what this function returns -// for inputs > INT_MAX. However this case should not error or GOOGLE_CHECK-fail, -// because the full size_t resolution is still returned from ByteSizeLong() and -// checked against INT_MAX; we can catch the overflow there. -inline int ToCachedSize(size_t size) { - return static_cast<int>(size); +struct LIBPROTOBUF_EXPORT FieldMetadata { + uint32 offset; // offset of this field in the struct + uint32 tag; // field * 8 + wire_type + // byte offset * 8 + bit_offset; + // if the high bit is set then this is the byte offset of the oneof_case + // for this field. + uint32 has_offset; + uint32 type; // the type of this field. + const void* ptr; // auxiliary data + + // From the serializer point of view each fundamental type can occur in + // 4 different ways. For simplicity we treat all combinations as a cartesion + // product although not all combinations are allowed. + enum FieldTypeClass { + kPresence, + kNoPresence, + kRepeated, + kPacked, + kOneOf, + kNumTypeClasses // must be last enum + }; + // C++ protobuf has 20 fundamental types, were we added Cord and StringPiece + // and also distinquish the same types if they have different wire format. + enum { + kCordType = 19, + kStringPieceType = 20, + kNumTypes = 20, + kSpecial = kNumTypes * kNumTypeClasses, + }; + + static int CalculateType(int fundamental_type, FieldTypeClass type_class); +}; + +inline bool IsPresent(const void* base, uint32 hasbit) { + const uint32* has_bits_array = static_cast<const uint32*>(base); + return has_bits_array[hasbit / 32] & (1u << (hasbit & 31)); +} + +inline bool IsOneofPresent(const void* base, uint32 offset, uint32 tag) { + const uint32* oneof = + reinterpret_cast<const uint32*>(static_cast<const uint8*>(base) + offset); + return *oneof == tag >> 3; +} + +typedef void (*SpecialSerializer)(const uint8* base, uint32 offset, uint32 tag, + uint32 has_offset, + ::google::protobuf::io::CodedOutputStream* output); + +LIBPROTOBUF_EXPORT void ExtensionSerializer(const uint8* base, uint32 offset, uint32 tag, + uint32 has_offset, + ::google::protobuf::io::CodedOutputStream* output); +LIBPROTOBUF_EXPORT void UnknownFieldSerializerLite(const uint8* base, uint32 offset, uint32 tag, + uint32 has_offset, + ::google::protobuf::io::CodedOutputStream* output); + +struct SerializationTable { + int num_fields; + const FieldMetadata* field_table; +}; + +LIBPROTOBUF_EXPORT void SerializeInternal(const uint8* base, const FieldMetadata* table, + int num_fields, ::google::protobuf::io::CodedOutputStream* output); + +inline void TableSerialize(const ::google::protobuf::MessageLite& msg, + const SerializationTable* table, + ::google::protobuf::io::CodedOutputStream* output) { + const FieldMetadata* field_table = table->field_table; + int num_fields = table->num_fields - 1; + const uint8* base = reinterpret_cast<const uint8*>(&msg); + // TODO(gerbens) This skips the first test if we could use the fast + // array serialization path, we should make this + // int cached_size = + // *reinterpret_cast<const int32*>(base + field_table->offset); + // SerializeWithCachedSize(msg, field_table + 1, num_fields, cached_size, ...) + // But we keep conformance with the old way for now. + SerializeInternal(base, field_table + 1, num_fields, output); } -// For cases where a legacy function returns an integer size. We GOOGLE_DCHECK() that -// the conversion will fit within an integer; if this is false then we are -// losing information. -inline int ToIntSize(size_t size) { - GOOGLE_DCHECK_LE(size, static_cast<size_t>(INT_MAX)); - return static_cast<int>(size); +uint8* SerializeInternalToArray(const uint8* base, const FieldMetadata* table, + int num_fields, bool is_deterministic, + uint8* buffer); + +inline uint8* TableSerializeToArray(const ::google::protobuf::MessageLite& msg, + const SerializationTable* table, + bool is_deterministic, uint8* buffer) { + const uint8* base = reinterpret_cast<const uint8*>(&msg); + const FieldMetadata* field_table = table->field_table + 1; + int num_fields = table->num_fields - 1; + return SerializeInternalToArray(base, field_table, num_fields, + is_deterministic, buffer); } -// We mainly calculate sizes in terms of size_t, but some functions that compute -// sizes return "int". These int sizes are expected to always be positive. -// This function is more efficient than casting an int to size_t directly on -// 64-bit platforms because it avoids making the compiler emit a sign extending -// instruction, which we don't want and don't want to pay for. -inline size_t FromIntSize(int size) { - // Convert to unsigned before widening so sign extension is not necessary. - return static_cast<unsigned int>(size); +template <typename T> +struct CompareHelper { + bool operator()(const T& a, const T& b) { return a < b; } +}; + +template <> +struct CompareHelper<ArenaStringPtr> { + bool operator()(const ArenaStringPtr& a, const ArenaStringPtr& b) { + return a.Get() < b.Get(); + } +}; + +struct CompareMapKey { + template <typename T> + bool operator()(const MapEntryHelper<T>& a, const MapEntryHelper<T>& b) { + return Compare(a.key_, b.key_); + } + template <typename T> + bool Compare(const T& a, const T& b) { + return CompareHelper<T>()(a, b); + } +}; + +template <typename MapFieldType, const SerializationTable* table> +void MapFieldSerializer(const uint8* base, uint32 offset, uint32 tag, + uint32 has_offset, + ::google::protobuf::io::CodedOutputStream* output) { + typedef MapEntryHelper<typename MapFieldType::EntryTypeTrait> Entry; + typedef typename MapFieldType::MapType::const_iterator Iter; + + const MapFieldType& map_field = + *reinterpret_cast<const MapFieldType*>(base + offset); + const SerializationTable* t = + table + + has_offset; // has_offset is overloaded for maps to mean table offset + if (!output->IsSerializationDeterministic()) { + for (Iter it = map_field.GetMap().begin(); it != map_field.GetMap().end(); + ++it) { + Entry map_entry(*it); + output->WriteVarint32(tag); + output->WriteVarint32(map_entry._cached_size_); + SerializeInternal(reinterpret_cast<const uint8*>(&map_entry), + t->field_table, t->num_fields, output); + } + } else { + std::vector<Entry> v; + for (Iter it = map_field.GetMap().begin(); it != map_field.GetMap().end(); + ++it) { + v.push_back(Entry(*it)); + } + std::sort(v.begin(), v.end(), CompareMapKey()); + for (int i = 0; i < v.size(); i++) { + output->WriteVarint32(tag); + output->WriteVarint32(v[i]._cached_size_); + SerializeInternal(reinterpret_cast<const uint8*>(&v[i]), t->field_table, + t->num_fields, output); + } + } } } // namespace internal diff --git a/src/google/protobuf/io/coded_stream.cc b/src/google/protobuf/io/coded_stream.cc index df4250e5..17eb0ffa 100644 --- a/src/google/protobuf/io/coded_stream.cc +++ b/src/google/protobuf/io/coded_stream.cc @@ -197,17 +197,7 @@ void CodedInputStream::PrintTotalBytesLimitError() { "in google/protobuf/io/coded_stream.h."; } -bool CodedInputStream::Skip(int count) { - if (count < 0) return false; // security: count is often user-supplied - - const int original_buffer_size = BufferSize(); - - if (count <= original_buffer_size) { - // Just skipping within the current buffer. Easy. - Advance(count); - return true; - } - +bool CodedInputStream::SkipFallback(int count, int original_buffer_size) { if (buffer_size_after_limit_ > 0) { // We hit a limit inside this buffer. Advance to the limit and fail. Advance(original_buffer_size); diff --git a/src/google/protobuf/io/coded_stream.h b/src/google/protobuf/io/coded_stream.h index 20d86143..bce05a39 100644 --- a/src/google/protobuf/io/coded_stream.h +++ b/src/google/protobuf/io/coded_stream.h @@ -184,7 +184,7 @@ class LIBPROTOBUF_EXPORT CodedInputStream { // Skips a number of bytes. Returns false if an underlying read error // occurs. - bool Skip(int count); + inline bool Skip(int count); // Sets *data to point directly at the unread part of the CodedInputStream's // underlying buffer, and *size to the size of that buffer, but does not @@ -261,7 +261,10 @@ class LIBPROTOBUF_EXPORT CodedInputStream { // Always inline because this is only called in one place per parse loop // but it is called for every iteration of said loop, so it should be fast. // GCC doesn't want to inline this by default. - GOOGLE_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTag(); + GOOGLE_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTag() { + return last_tag_ = ReadTagNoLastTag(); + } + GOOGLE_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTagNoLastTag(); @@ -274,7 +277,12 @@ class LIBPROTOBUF_EXPORT CodedInputStream { // because that can arise in several ways, and for best performance we want // to avoid an extra "is tag == 0?" check here.) GOOGLE_ATTRIBUTE_ALWAYS_INLINE std::pair<uint32, bool> ReadTagWithCutoff( - uint32 cutoff); + uint32 cutoff) { + std::pair<uint32, bool> result = ReadTagWithCutoffNoLastTag(cutoff); + last_tag_ = result.first; + return result; + } + GOOGLE_ATTRIBUTE_ALWAYS_INLINE std::pair<uint32, bool> ReadTagWithCutoffNoLastTag( uint32 cutoff); @@ -316,6 +324,7 @@ class LIBPROTOBUF_EXPORT CodedInputStream { // tag to make sure it had the right number, so it calls LastTagWas() on // return from the embedded parser to check. bool LastTagWas(uint32 expected); + void SetLastTag(uint32 tag) { last_tag_ = tag; } // When parsing message (but NOT a group), this method must be called // immediately after MergeFromCodedStream() returns (if it returns true) @@ -584,6 +593,9 @@ class LIBPROTOBUF_EXPORT CodedInputStream { // Private member functions. + // Fallback when Skip() goes past the end of the current buffer. + bool SkipFallback(int count, int original_buffer_size); + // Advance the buffer by a given number of bytes. void Advance(int amount); @@ -621,12 +633,6 @@ class LIBPROTOBUF_EXPORT CodedInputStream { bool ReadLittleEndian32Fallback(uint32* value); bool ReadLittleEndian64Fallback(uint64* value); - template<bool update_last_tag> - GOOGLE_ATTRIBUTE_ALWAYS_INLINE uint32 ReadTagImplementation(); - template<bool update_last_tag> - GOOGLE_ATTRIBUTE_ALWAYS_INLINE - std::pair<uint32, bool> ReadTagWithCutoffImplementation(uint32 cutoff); - // Fallback/slow methods for reading tags. These do not update last_tag_, // but will set legitimate_message_end_ if we are at the end of the input // stream. @@ -1018,48 +1024,21 @@ inline bool CodedInputStream::ReadLittleEndian64(uint64* value) { #endif } -inline uint32 CodedInputStream::ReadTag() { - return ReadTagImplementation<true>(); -} - inline uint32 CodedInputStream::ReadTagNoLastTag() { - return ReadTagImplementation<false>(); -} - -template<bool update_last_tag> -inline uint32 CodedInputStream::ReadTagImplementation() { uint32 v = 0; if (GOOGLE_PREDICT_TRUE(buffer_ < buffer_end_)) { v = *buffer_; if (v < 0x80) { - if (update_last_tag) { - last_tag_ = v; - } Advance(1); return v; } } v = ReadTagFallback(v); - if (update_last_tag) { - last_tag_ = v; - } return v; } -inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoff( - uint32 cutoff) { - return ReadTagWithCutoffImplementation<true>(cutoff); -} - inline std::pair<uint32, bool> CodedInputStream::ReadTagWithCutoffNoLastTag( uint32 cutoff) { - return ReadTagWithCutoffImplementation<false>(cutoff); -} - -template<bool update_last_tag> -inline std::pair<uint32, bool> -CodedInputStream::ReadTagWithCutoffImplementation( - uint32 cutoff) { // In performance-sensitive code we can expect cutoff to be a compile-time // constant, and things like "cutoff >= kMax1ByteVarint" to be evaluated at // compile time. @@ -1072,9 +1051,6 @@ CodedInputStream::ReadTagWithCutoffImplementation( if (static_cast<int8>(buffer_[0]) > 0) { const uint32 kMax1ByteVarint = 0x7f; uint32 tag = buffer_[0]; - if (update_last_tag) { - last_tag_ = tag; - } Advance(1); return std::make_pair(tag, cutoff >= kMax1ByteVarint || tag <= cutoff); } @@ -1086,9 +1062,6 @@ CodedInputStream::ReadTagWithCutoffImplementation( GOOGLE_PREDICT_TRUE((buffer_[0] & ~buffer_[1]) >= 0x80)) { const uint32 kMax2ByteVarint = (0x7f << 7) + 0x7f; uint32 tag = (1u << 7) * buffer_[1] + (buffer_[0] - 0x80); - if (update_last_tag) { - last_tag_ = tag; - } Advance(2); // It might make sense to test for tag == 0 now, but it is so rare that // that we don't bother. A varint-encoded 0 should be one byte unless @@ -1102,9 +1075,6 @@ CodedInputStream::ReadTagWithCutoffImplementation( } // Slow path const uint32 tag = ReadTagFallback(first_byte_or_zero); - if (update_last_tag) { - last_tag_ = tag; - } return std::make_pair(tag, static_cast<uint32>(tag - 1) < cutoff); } @@ -1430,6 +1400,20 @@ inline bool CodedInputStream::IsFlat() const { return input_ == NULL; } +inline bool CodedInputStream::Skip(int count) { + if (count < 0) return false; // security: count is often user-supplied + + const int original_buffer_size = BufferSize(); + + if (count <= original_buffer_size) { + // Just skipping within the current buffer. Easy. + Advance(count); + return true; + } + + return SkipFallback(count, original_buffer_size); +} + } // namespace io } // namespace protobuf diff --git a/src/google/protobuf/io/printer.cc b/src/google/protobuf/io/printer.cc index 99e895f5..8493268d 100644 --- a/src/google/protobuf/io/printer.cc +++ b/src/google/protobuf/io/printer.cc @@ -111,6 +111,7 @@ void Printer::Print(const std::map<string, string>& variables, int size = strlen(text); int pos = 0; // The number of bytes we've written so far. substitutions_.clear(); + line_start_variables_.clear(); for (int i = 0; i < size; i++) { if (text[i] == '\n') { @@ -122,6 +123,7 @@ void Printer::Print(const std::map<string, string>& variables, // Setting this true will cause the next WriteRaw() to insert an indent // first. at_start_of_line_ = true; + line_start_variables_.clear(); } else if (text[i] == variable_delimiter_) { // Saw the start of a variable name. @@ -148,12 +150,15 @@ void Printer::Print(const std::map<string, string>& variables, if (iter == variables.end()) { GOOGLE_LOG(DFATAL) << " Undefined variable: " << varname; } else { - size_t begin = offset_; + if (at_start_of_line_ && iter->second.empty()) { + line_start_variables_.push_back(varname); + } WriteRaw(iter->second.data(), iter->second.size()); std::pair<std::map<string, std::pair<size_t, size_t> >::iterator, bool> - inserted = substitutions_.insert( - std::make_pair(varname, std::make_pair(begin, offset_))); + inserted = substitutions_.insert(std::make_pair( + varname, + std::make_pair(offset_ - iter->second.size(), offset_))); if (!inserted.second) { // This variable was used multiple times. Make its span have // negative length so we can detect it if it gets used in an @@ -319,10 +324,29 @@ void Printer::WriteRaw(const char* data, int size) { if (at_start_of_line_ && (size > 0) && (data[0] != '\n')) { // Insert an indent. at_start_of_line_ = false; - WriteRaw(indent_.data(), indent_.size()); + CopyToBuffer(indent_.data(), indent_.size()); if (failed_) return; + // Fix up empty variables (e.g., "{") that should be annotated as + // coming after the indent. + for (std::vector<string>::iterator i = line_start_variables_.begin(); + i != line_start_variables_.end(); ++i) { + substitutions_[*i].first += indent_.size(); + substitutions_[*i].second += indent_.size(); + } } + // If we're going to write any data, clear line_start_variables_, since + // we've either updated them in the block above or they no longer refer to + // the current line. + line_start_variables_.clear(); + + CopyToBuffer(data, size); +} + +void Printer::CopyToBuffer(const char* data, int size) { + if (failed_) return; + if (size == 0) return; + while (size > buffer_size_) { // Data exceeds space in the buffer. Copy what we can and request a // new buffer. diff --git a/src/google/protobuf/io/printer.h b/src/google/protobuf/io/printer.h index e666445b..d11745ce 100644 --- a/src/google/protobuf/io/printer.h +++ b/src/google/protobuf/io/printer.h @@ -157,7 +157,7 @@ class AnnotationProtoCollector : public AnnotationCollector { // vars["function"] = "call"; // vars["mark"] = ""; // printer.Print(vars, "$function$($foo$,$foo$)$mark$"); -// printer.Annotate("function", "rmark", call_); +// printer.Annotate("function", "mark", call_); // // This code associates the span covering "call(bar,bar)" in the output with the // call_ descriptor. @@ -311,6 +311,9 @@ class LIBPROTOBUF_EXPORT Printer { void Annotate(const char* begin_varname, const char* end_varname, const string& file_path, const std::vector<int>& path); + // Copy size worth of bytes from data to buffer_. + void CopyToBuffer(const char* data, int size); + const char variable_delimiter_; ZeroCopyOutputStream* const output_; @@ -334,6 +337,11 @@ class LIBPROTOBUF_EXPORT Printer { // length of the substituted string). std::map<string, std::pair<size_t, size_t> > substitutions_; + // Keeps track of the keys in substitutions_ that need to be updated when + // indents are inserted. These are keys that refer to the beginning of the + // current line. + std::vector<string> line_start_variables_; + // Returns true and sets range to the substitution range in the output for // varname if varname was used once in the last call to Print. If varname // was not used, or if it was used multiple times, returns false (and diff --git a/src/google/protobuf/io/printer_unittest.cc b/src/google/protobuf/io/printer_unittest.cc index 0435228a..d0a0ebee 100644 --- a/src/google/protobuf/io/printer_unittest.cc +++ b/src/google/protobuf/io/printer_unittest.cc @@ -360,6 +360,83 @@ TEST(Printer, AnnotateDespiteUnrelatedMultipleUses) { EXPECT_EQ(7, bar->end()); } +TEST(Printer, AnnotateIndent) { + char buffer[8192]; + ArrayOutputStream output(buffer, sizeof(buffer)); + GeneratedCodeInfo info; + AnnotationProtoCollector<GeneratedCodeInfo> info_collector(&info); + { + Printer printer(&output, '$', &info_collector); + printer.Print("0\n"); + printer.Indent(); + printer.Print("$foo$", "foo", "4"); + std::vector<int> path; + path.push_back(44); + MockDescriptor descriptor("path", path); + printer.Annotate("foo", &descriptor); + printer.Print(",\n"); + printer.Print("$bar$", "bar", "9"); + path[0] = 99; + MockDescriptor descriptor_two("path", path); + printer.Annotate("bar", &descriptor_two); + printer.Print("\n${$$D$$}$\n", "{", "", "}", "", "D", "d"); + path[0] = 1313; + MockDescriptor descriptor_three("path", path); + printer.Annotate("{", "}", &descriptor_three); + printer.Outdent(); + printer.Print("\n"); + } + buffer[output.ByteCount()] = '\0'; + EXPECT_STREQ("0\n 4,\n 9\n d\n\n", buffer); + ASSERT_EQ(3, info.annotation_size()); + const GeneratedCodeInfo::Annotation* foo = &info.annotation(0); + ASSERT_EQ(1, foo->path_size()); + EXPECT_EQ(44, foo->path(0)); + EXPECT_EQ("path", foo->source_file()); + EXPECT_EQ(4, foo->begin()); + EXPECT_EQ(5, foo->end()); + const GeneratedCodeInfo::Annotation* bar = &info.annotation(1); + ASSERT_EQ(1, bar->path_size()); + EXPECT_EQ(99, bar->path(0)); + EXPECT_EQ("path", bar->source_file()); + EXPECT_EQ(9, bar->begin()); + EXPECT_EQ(10, bar->end()); + const GeneratedCodeInfo::Annotation* braces = &info.annotation(2); + ASSERT_EQ(1, braces->path_size()); + EXPECT_EQ(1313, braces->path(0)); + EXPECT_EQ("path", braces->source_file()); + EXPECT_EQ(13, braces->begin()); + EXPECT_EQ(14, braces->end()); +} + +TEST(Printer, AnnotateIndentNewline) { + char buffer[8192]; + ArrayOutputStream output(buffer, sizeof(buffer)); + GeneratedCodeInfo info; + AnnotationProtoCollector<GeneratedCodeInfo> info_collector(&info); + { + Printer printer(&output, '$', &info_collector); + printer.Indent(); + printer.Print("$A$$N$$B$C\n", "A", "", "N", "\nz", "B", ""); + std::vector<int> path; + path.push_back(0); + MockDescriptor descriptor("path", path); + printer.Annotate("A", "B", &descriptor); + printer.Outdent(); + printer.Print("\n"); + } + buffer[output.ByteCount()] = '\0'; + EXPECT_STREQ("\nz C\n\n", buffer); + ASSERT_EQ(1, info.annotation_size()); + const GeneratedCodeInfo::Annotation* ab = &info.annotation(0); + ASSERT_EQ(1, ab->path_size()); + EXPECT_EQ(0, ab->path(0)); + EXPECT_EQ("path", ab->source_file()); + EXPECT_EQ(0, ab->begin()); + EXPECT_EQ(4, ab->end()); +} + + TEST(Printer, Indenting) { char buffer[8192]; diff --git a/src/google/protobuf/io/zero_copy_stream.cc b/src/google/protobuf/io/zero_copy_stream.cc index 186de001..f81555e5 100644 --- a/src/google/protobuf/io/zero_copy_stream.cc +++ b/src/google/protobuf/io/zero_copy_stream.cc @@ -41,9 +41,6 @@ namespace google { namespace protobuf { namespace io { -ZeroCopyInputStream::~ZeroCopyInputStream() {} -ZeroCopyOutputStream::~ZeroCopyOutputStream() {} - bool ZeroCopyOutputStream::WriteAliasedRaw(const void* /* data */, int /* size */) { diff --git a/src/google/protobuf/io/zero_copy_stream.h b/src/google/protobuf/io/zero_copy_stream.h index 52650fc6..62ace7ae 100644 --- a/src/google/protobuf/io/zero_copy_stream.h +++ b/src/google/protobuf/io/zero_copy_stream.h @@ -123,8 +123,8 @@ class ZeroCopyOutputStream; // copying. class LIBPROTOBUF_EXPORT ZeroCopyInputStream { public: - inline ZeroCopyInputStream() {} - virtual ~ZeroCopyInputStream(); + ZeroCopyInputStream() {} + virtual ~ZeroCopyInputStream() {} // Obtains a chunk of data from the stream. // @@ -180,8 +180,8 @@ class LIBPROTOBUF_EXPORT ZeroCopyInputStream { // copying. class LIBPROTOBUF_EXPORT ZeroCopyOutputStream { public: - inline ZeroCopyOutputStream() {} - virtual ~ZeroCopyOutputStream(); + ZeroCopyOutputStream() {} + virtual ~ZeroCopyOutputStream() {} // Obtains a buffer into which data can be written. Any data written // into this buffer will eventually (maybe instantly, maybe later on) diff --git a/src/google/protobuf/io/zero_copy_stream_impl.cc b/src/google/protobuf/io/zero_copy_stream_impl.cc index 109c55c1..d638ec05 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl.cc +++ b/src/google/protobuf/io/zero_copy_stream_impl.cc @@ -81,8 +81,6 @@ FileInputStream::FileInputStream(int file_descriptor, int block_size) impl_(©ing_input_, block_size) { } -FileInputStream::~FileInputStream() {} - bool FileInputStream::Close() { return copying_input_.Close(); } @@ -273,8 +271,6 @@ bool FileOutputStream::CopyingFileOutputStream::Write( IstreamInputStream::IstreamInputStream(std::istream* input, int block_size) : copying_input_(input), impl_(©ing_input_, block_size) {} -IstreamInputStream::~IstreamInputStream() {} - bool IstreamInputStream::Next(const void** data, int* size) { return impl_.Next(data, size); } @@ -348,9 +344,6 @@ ConcatenatingInputStream::ConcatenatingInputStream( : streams_(streams), stream_count_(count), bytes_retired_(0) { } -ConcatenatingInputStream::~ConcatenatingInputStream() { -} - bool ConcatenatingInputStream::Next(const void** data, int* size) { while (stream_count_ > 0) { if (streams_[0]->Next(data, size)) return true; diff --git a/src/google/protobuf/io/zero_copy_stream_impl.h b/src/google/protobuf/io/zero_copy_stream_impl.h index 3365790e..ea978bfb 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl.h +++ b/src/google/protobuf/io/zero_copy_stream_impl.h @@ -67,7 +67,6 @@ class LIBPROTOBUF_EXPORT FileInputStream : public ZeroCopyInputStream { // should be read and returned with each call to Next(). Otherwise, // a reasonable default is used. explicit FileInputStream(int file_descriptor, int block_size = -1); - ~FileInputStream(); // Flushes any buffers and closes the underlying file. Returns false if // an error occurs during the process; use GetErrno() to examine the error. @@ -219,7 +218,6 @@ class LIBPROTOBUF_EXPORT IstreamInputStream : public ZeroCopyInputStream { // should be read and returned with each call to Next(). Otherwise, // a reasonable default is used. explicit IstreamInputStream(std::istream* stream, int block_size = -1); - ~IstreamInputStream(); // implements ZeroCopyInputStream ---------------------------------- bool Next(const void** data, int* size); @@ -306,7 +304,6 @@ class LIBPROTOBUF_EXPORT ConcatenatingInputStream : public ZeroCopyInputStream { // All streams passed in as well as the array itself must remain valid // until the ConcatenatingInputStream is destroyed. ConcatenatingInputStream(ZeroCopyInputStream* const streams[], int count); - ~ConcatenatingInputStream(); // implements ZeroCopyInputStream ---------------------------------- bool Next(const void** data, int* size); diff --git a/src/google/protobuf/io/zero_copy_stream_impl_lite.cc b/src/google/protobuf/io/zero_copy_stream_impl_lite.cc index e6ca88c2..60c71c80 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl_lite.cc +++ b/src/google/protobuf/io/zero_copy_stream_impl_lite.cc @@ -64,9 +64,6 @@ ArrayInputStream::ArrayInputStream(const void* data, int size, last_returned_size_(0) { } -ArrayInputStream::~ArrayInputStream() { -} - bool ArrayInputStream::Next(const void** data, int* size) { if (position_ < size_) { last_returned_size_ = std::min(block_size_, size_ - position_); @@ -117,9 +114,6 @@ ArrayOutputStream::ArrayOutputStream(void* data, int size, int block_size) last_returned_size_(0) { } -ArrayOutputStream::~ArrayOutputStream() { -} - bool ArrayOutputStream::Next(void** data, int* size) { if (position_ < size_) { last_returned_size_ = std::min(block_size_, size_ - position_); @@ -153,9 +147,6 @@ StringOutputStream::StringOutputStream(string* target) : target_(target) { } -StringOutputStream::~StringOutputStream() { -} - bool StringOutputStream::Next(void** data, int* size) { GOOGLE_CHECK(target_ != NULL); int old_size = target_->size(); @@ -212,9 +203,6 @@ LazyStringOutputStream::LazyStringOutputStream( string_is_set_(false) { } -LazyStringOutputStream::~LazyStringOutputStream() { -} - bool LazyStringOutputStream::Next(void** data, int* size) { if (!string_is_set_) { SetString(callback_->Run()); @@ -229,8 +217,6 @@ int64 LazyStringOutputStream::ByteCount() const { // =================================================================== -CopyingInputStream::~CopyingInputStream() {} - int CopyingInputStream::Skip(int count) { char junk[4096]; int skipped = 0; @@ -350,8 +336,6 @@ void CopyingInputStreamAdaptor::FreeBuffer() { // =================================================================== -CopyingOutputStream::~CopyingOutputStream() {} - CopyingOutputStreamAdaptor::CopyingOutputStreamAdaptor( CopyingOutputStream* copying_stream, int block_size) : copying_stream_(copying_stream), diff --git a/src/google/protobuf/io/zero_copy_stream_impl_lite.h b/src/google/protobuf/io/zero_copy_stream_impl_lite.h index 6db1d695..a7bbc625 100644 --- a/src/google/protobuf/io/zero_copy_stream_impl_lite.h +++ b/src/google/protobuf/io/zero_copy_stream_impl_lite.h @@ -73,7 +73,6 @@ class LIBPROTOBUF_EXPORT ArrayInputStream : public ZeroCopyInputStream { // useful for testing; in production you would probably never want to set // it. ArrayInputStream(const void* data, int size, int block_size = -1); - ~ArrayInputStream(); // implements ZeroCopyInputStream ---------------------------------- bool Next(const void** data, int* size); @@ -107,7 +106,6 @@ class LIBPROTOBUF_EXPORT ArrayOutputStream : public ZeroCopyOutputStream { // useful for testing; in production you would probably never want to set // it. ArrayOutputStream(void* data, int size, int block_size = -1); - ~ArrayOutputStream(); // implements ZeroCopyOutputStream --------------------------------- bool Next(void** data, int* size); @@ -141,7 +139,6 @@ class LIBPROTOBUF_EXPORT StringOutputStream : public ZeroCopyOutputStream { // the first call to Next() will return at least n bytes of buffer // space. explicit StringOutputStream(string* target); - ~StringOutputStream(); // implements ZeroCopyOutputStream --------------------------------- bool Next(void** data, int* size); @@ -167,7 +164,6 @@ class LIBPROTOBUF_EXPORT LazyStringOutputStream : public StringOutputStream { // Callback should be permanent (non-self-deleting). Ownership is transferred // to the LazyStringOutputStream. explicit LazyStringOutputStream(ResultCallback<string*>* callback); - ~LazyStringOutputStream(); // implements ZeroCopyOutputStream, overriding StringOutputStream ----------- bool Next(void** data, int* size); @@ -199,7 +195,7 @@ class LIBPROTOBUF_EXPORT LazyStringOutputStream : public StringOutputStream { // in large blocks. class LIBPROTOBUF_EXPORT CopyingInputStream { public: - virtual ~CopyingInputStream(); + virtual ~CopyingInputStream() {} // Reads up to "size" bytes into the given buffer. Returns the number of // bytes read. Read() waits until at least one byte is available, or @@ -293,7 +289,7 @@ class LIBPROTOBUF_EXPORT CopyingInputStreamAdaptor : public ZeroCopyInputStream // in large blocks. class LIBPROTOBUF_EXPORT CopyingOutputStream { public: - virtual ~CopyingOutputStream(); + virtual ~CopyingOutputStream() {} // Writes "size" bytes from the given buffer to the output. Returns true // if successful, false on a write error. diff --git a/src/google/protobuf/lite_unittest.cc b/src/google/protobuf/lite_unittest.cc index 2f5268af..6cf16629 100644 --- a/src/google/protobuf/lite_unittest.cc +++ b/src/google/protobuf/lite_unittest.cc @@ -48,6 +48,8 @@ #include <google/protobuf/stubs/strutil.h> +using std::string; + namespace { // Helper methods to test parsing merge behavior. void ExpectMessageMerged(const google::protobuf::unittest::TestAllTypesLite& message) { @@ -71,7 +73,7 @@ void SetAllTypesInEmptyMessageUnknownFields( protobuf_unittest::TestAllTypesLite message; google::protobuf::TestUtilLite::ExpectClear(message); google::protobuf::TestUtilLite::SetAllFields(&message); - std::string data = message.SerializeAsString(); + string data = message.SerializeAsString(); empty_message->ParseFromString(data); } @@ -83,14 +85,14 @@ void SetSomeTypesInEmptyMessageUnknownFields( message.set_optional_int64(102); message.set_optional_uint32(103); message.set_optional_uint64(104); - std::string data = message.SerializeAsString(); + string data = message.SerializeAsString(); empty_message->ParseFromString(data); } } // namespace TEST(Lite, AllLite1) { - std::string data; + string data; { protobuf_unittest::TestAllTypesLite message, message2, message3; @@ -110,13 +112,13 @@ TEST(Lite, AllLite1) { } TEST(Lite, AllLite2) { - std::string data; + string data; { protobuf_unittest::TestAllExtensionsLite message, message2, message3; google::protobuf::TestUtilLite::ExpectExtensionsClear(message); google::protobuf::TestUtilLite::SetAllExtensions(&message); message2.CopyFrom(message); - std::string extensions_data = message.SerializeAsString(); + string extensions_data = message.SerializeAsString(); message3.ParseFromString(extensions_data); google::protobuf::TestUtilLite::ExpectAllExtensionsSet(message); google::protobuf::TestUtilLite::ExpectAllExtensionsSet(message2); @@ -129,7 +131,7 @@ TEST(Lite, AllLite2) { } TEST(Lite, AllLite3) { - std::string data, packed_data; + string data, packed_data; { protobuf_unittest::TestPackedTypesLite message, message2, message3; @@ -152,7 +154,7 @@ TEST(Lite, AllLite3) { google::protobuf::TestUtilLite::ExpectPackedExtensionsClear(message); google::protobuf::TestUtilLite::SetPackedExtensions(&message); message2.CopyFrom(message); - std::string packed_extensions_data = message.SerializeAsString(); + string packed_extensions_data = message.SerializeAsString(); EXPECT_EQ(packed_extensions_data, packed_data); message3.ParseFromString(packed_extensions_data); google::protobuf::TestUtilLite::ExpectPackedExtensionsSet(message); @@ -166,7 +168,7 @@ TEST(Lite, AllLite3) { } TEST(Lite, AllLite5) { - std::string data; + string data; { // Test that if an optional or required message/group field appears multiple @@ -200,7 +202,7 @@ TEST(Lite, AllLite5) { #undef ASSIGN_REPEATED_GROUP - std::string buffer; + string buffer; generator.SerializeToString(&buffer); google::protobuf::unittest::TestParsingMergeLite parsing_merge; parsing_merge.ParseFromString(buffer); @@ -223,7 +225,7 @@ TEST(Lite, AllLite5) { } TEST(Lite, AllLite6) { - std::string data; + string data; // Test unknown fields support for lite messages. { @@ -244,7 +246,7 @@ TEST(Lite, AllLite6) { } TEST(Lite, AllLite7) { - std::string data; + string data; { protobuf_unittest::TestAllExtensionsLite message, message2; @@ -264,7 +266,7 @@ TEST(Lite, AllLite7) { } TEST(Lite, AllLite8) { - std::string data; + string data; { protobuf_unittest::TestPackedTypesLite message, message2; @@ -284,7 +286,7 @@ TEST(Lite, AllLite8) { } TEST(Lite, AllLite9) { - std::string data; + string data; { protobuf_unittest::TestPackedExtensionsLite message, message2; @@ -304,7 +306,7 @@ TEST(Lite, AllLite9) { } TEST(Lite, AllLite10) { - std::string data; + string data; { // Test Unknown fields swap @@ -312,7 +314,7 @@ TEST(Lite, AllLite10) { SetAllTypesInEmptyMessageUnknownFields(&empty_message); SetSomeTypesInEmptyMessageUnknownFields(&empty_message2); data = empty_message.SerializeAsString(); - std::string data2 = empty_message2.SerializeAsString(); + string data2 = empty_message2.SerializeAsString(); empty_message.Swap(&empty_message2); EXPECT_EQ(data, empty_message2.SerializeAsString()); EXPECT_EQ(data2, empty_message.SerializeAsString()); @@ -320,7 +322,7 @@ TEST(Lite, AllLite10) { } TEST(Lite, AllLite11) { - std::string data; + string data; { // Test unknown fields swap with self @@ -333,7 +335,7 @@ TEST(Lite, AllLite11) { } TEST(Lite, AllLite12) { - std::string data; + string data; { // Test MergeFrom with unknown fields @@ -363,12 +365,12 @@ TEST(Lite, AllLite12) { } TEST(Lite, AllLite13) { - std::string data; + string data; { // Test unknown enum value protobuf_unittest::TestAllTypesLite message; - std::string buffer; + string buffer; { google::protobuf::io::StringOutputStream output_stream(&buffer); google::protobuf::io::CodedOutputStream coded_output(&output_stream); @@ -388,7 +390,7 @@ TEST(Lite, AllLite13) { } TEST(Lite, AllLite14) { - std::string data; + string data; { // Test Clear with unknown fields @@ -402,7 +404,7 @@ TEST(Lite, AllLite14) { // Tests for map lite ============================================= TEST(Lite, AllLite15) { - std::string data; + string data; { // Accessors @@ -417,7 +419,7 @@ TEST(Lite, AllLite15) { } TEST(Lite, AllLite16) { - std::string data; + string data; { // SetMapFieldsInitialized @@ -429,7 +431,7 @@ TEST(Lite, AllLite16) { } TEST(Lite, AllLite17) { - std::string data; + string data; { // Clear @@ -442,7 +444,7 @@ TEST(Lite, AllLite17) { } TEST(Lite, AllLite18) { - std::string data; + string data; { // ClearMessageMap @@ -455,7 +457,7 @@ TEST(Lite, AllLite18) { } TEST(Lite, AllLite19) { - std::string data; + string data; { // CopyFrom @@ -472,7 +474,7 @@ TEST(Lite, AllLite19) { } TEST(Lite, AllLite20) { - std::string data; + string data; { // CopyFromMessageMap @@ -490,7 +492,7 @@ TEST(Lite, AllLite20) { } TEST(Lite, AllLite21) { - std::string data; + string data; { // SwapWithEmpty @@ -507,7 +509,7 @@ TEST(Lite, AllLite21) { } TEST(Lite, AllLite22) { - std::string data; + string data; { // SwapWithSelf @@ -522,7 +524,7 @@ TEST(Lite, AllLite22) { } TEST(Lite, AllLite23) { - std::string data; + string data; { // SwapWithOther @@ -539,7 +541,7 @@ TEST(Lite, AllLite23) { } TEST(Lite, AllLite24) { - std::string data; + string data; { // CopyConstructor @@ -552,7 +554,7 @@ TEST(Lite, AllLite24) { } TEST(Lite, AllLite25) { - std::string data; + string data; { // CopyAssignmentOperator @@ -570,7 +572,7 @@ TEST(Lite, AllLite25) { } TEST(Lite, AllLite26) { - std::string data; + string data; { // NonEmptyMergeFrom @@ -592,7 +594,7 @@ TEST(Lite, AllLite26) { } TEST(Lite, AllLite27) { - std::string data; + string data; { // MergeFromMessageMap @@ -610,12 +612,12 @@ TEST(Lite, AllLite27) { } TEST(Lite, AllLite28) { - std::string data; + string data; { // Test the generated SerializeWithCachedSizesToArray() protobuf_unittest::TestMapLite message1, message2; - std::string data; + string data; google::protobuf::MapLiteTestUtil::SetMapFields(&message1); int size = message1.ByteSize(); data.resize(size); @@ -628,14 +630,14 @@ TEST(Lite, AllLite28) { } TEST(Lite, AllLite29) { - std::string data; + string data; { // Test the generated SerializeWithCachedSizes() protobuf_unittest::TestMapLite message1, message2; google::protobuf::MapLiteTestUtil::SetMapFields(&message1); int size = message1.ByteSize(); - std::string data; + string data; data.resize(size); { // Allow the output stream to buffer only one byte at a time. @@ -653,7 +655,7 @@ TEST(Lite, AllLite29) { TEST(Lite, AllLite32) { - std::string data; + string data; { // Proto2UnknownEnum @@ -662,7 +664,7 @@ TEST(Lite, AllLite32) { protobuf_unittest::E_PROTO2_MAP_ENUM_FOO_LITE; (*from.mutable_unknown_map_field())[0] = protobuf_unittest::E_PROTO2_MAP_ENUM_EXTRA_LITE; - std::string data; + string data; from.SerializeToString(&data); protobuf_unittest::TestEnumMapLite to; @@ -687,12 +689,12 @@ TEST(Lite, AllLite32) { } TEST(Lite, AllLite33) { - std::string data; + string data; { // StandardWireFormat protobuf_unittest::TestMapLite message; - std::string data = "\x0A\x04\x08\x01\x10\x01"; + string data = "\x0A\x04\x08\x01\x10\x01"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); @@ -701,14 +703,14 @@ TEST(Lite, AllLite33) { } TEST(Lite, AllLite34) { - std::string data; + string data; { // UnorderedWireFormat protobuf_unittest::TestMapLite message; // put value before key in wire format - std::string data = "\x0A\x04\x10\x01\x08\x02"; + string data = "\x0A\x04\x10\x01\x08\x02"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); @@ -717,14 +719,14 @@ TEST(Lite, AllLite34) { } TEST(Lite, AllLite35) { - std::string data; + string data; { // DuplicatedKeyWireFormat protobuf_unittest::TestMapLite message; // Two key fields in wire format - std::string data = "\x0A\x06\x08\x01\x08\x02\x10\x01"; + string data = "\x0A\x06\x08\x01\x08\x02\x10\x01"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); @@ -733,14 +735,14 @@ TEST(Lite, AllLite35) { } TEST(Lite, AllLite36) { - std::string data; + string data; { // DuplicatedValueWireFormat protobuf_unittest::TestMapLite message; // Two value fields in wire format - std::string data = "\x0A\x06\x08\x01\x10\x01\x10\x02"; + string data = "\x0A\x06\x08\x01\x10\x01\x10\x02"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); @@ -749,14 +751,14 @@ TEST(Lite, AllLite36) { } TEST(Lite, AllLite37) { - std::string data; + string data; { // MissedKeyWireFormat protobuf_unittest::TestMapLite message; // No key field in wire format - std::string data = "\x0A\x02\x10\x01"; + string data = "\x0A\x02\x10\x01"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); @@ -765,14 +767,14 @@ TEST(Lite, AllLite37) { } TEST(Lite, AllLite38) { - std::string data; + string data; { // MissedValueWireFormat protobuf_unittest::TestMapLite message; // No value field in wire format - std::string data = "\x0A\x02\x08\x01"; + string data = "\x0A\x02\x08\x01"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); @@ -781,14 +783,14 @@ TEST(Lite, AllLite38) { } TEST(Lite, AllLite39) { - std::string data; + string data; { // UnknownFieldWireFormat protobuf_unittest::TestMapLite message; // Unknown field in wire format - std::string data = "\x0A\x06\x08\x02\x10\x03\x18\x01"; + string data = "\x0A\x06\x08\x02\x10\x03\x18\x01"; EXPECT_TRUE(message.ParseFromString(data)); EXPECT_EQ(1, message.map_int32_int32().size()); @@ -797,21 +799,21 @@ TEST(Lite, AllLite39) { } TEST(Lite, AllLite40) { - std::string data; + string data; { // CorruptedWireFormat protobuf_unittest::TestMapLite message; // corrupted data in wire format - std::string data = "\x0A\x06\x08\x02\x11\x03"; + string data = "\x0A\x06\x08\x02\x11\x03"; EXPECT_FALSE(message.ParseFromString(data)); } } TEST(Lite, AllLite41) { - std::string data; + string data; { // IsInitialized @@ -830,7 +832,7 @@ TEST(Lite, AllLite41) { } TEST(Lite, AllLite42) { - std::string data; + string data; { // Check that adding more values to enum does not corrupt message @@ -839,7 +841,7 @@ TEST(Lite, AllLite42) { v2_message.set_int_field(800); // Set enum field to the value not understood by the old client. v2_message.set_enum_field(protobuf_unittest::V2_SECOND); - std::string v2_bytes = v2_message.SerializeAsString(); + string v2_bytes = v2_message.SerializeAsString(); protobuf_unittest::V1MessageLite v1_message; v1_message.ParseFromString(v2_bytes); @@ -850,7 +852,7 @@ TEST(Lite, AllLite42) { EXPECT_EQ(v1_message.enum_field(), protobuf_unittest::V1_FIRST); // However, when re-serialized, it should preserve enum value. - std::string v1_bytes = v1_message.SerializeAsString(); + string v1_bytes = v1_message.SerializeAsString(); protobuf_unittest::V2MessageLite same_v2_message; same_v2_message.ParseFromString(v1_bytes); @@ -858,6 +860,131 @@ TEST(Lite, AllLite42) { EXPECT_EQ(v2_message.int_field(), same_v2_message.int_field()); EXPECT_EQ(v2_message.enum_field(), same_v2_message.enum_field()); } +} + +// Test that when parsing a oneof, we can successfully clear whatever already +// happened to be stored in the oneof. +TEST(Lite, AllLite43) { + protobuf_unittest::TestOneofParsingLite message1; + + message1.set_oneof_int32(17); + string serialized; + EXPECT_TRUE(message1.SerializeToString(&serialized)); + + // Submessage + { + protobuf_unittest::TestOneofParsingLite message2; + message2.mutable_oneof_submessage(); + google::protobuf::io::CodedInputStream input_stream( + reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()), serialized.size()); + EXPECT_TRUE(message2.MergeFromCodedStream(&input_stream)); + EXPECT_EQ(17, message2.oneof_int32()); + } + + // String + { + protobuf_unittest::TestOneofParsingLite message2; + message2.set_oneof_string("string"); + google::protobuf::io::CodedInputStream input_stream( + reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()), serialized.size()); + EXPECT_TRUE(message2.MergeFromCodedStream(&input_stream)); + EXPECT_EQ(17, message2.oneof_int32()); + } + + // Bytes + { + protobuf_unittest::TestOneofParsingLite message2; + message2.set_oneof_bytes("bytes"); + google::protobuf::io::CodedInputStream input_stream( + reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()), serialized.size()); + EXPECT_TRUE(message2.MergeFromCodedStream(&input_stream)); + EXPECT_EQ(17, message2.oneof_int32()); + } +} + +// Verify that we can successfully parse fields of various types within oneof +// fields. We also verify that we can parse the same data twice into the same +// message. +TEST(Lite, AllLite44) { + // Int32 + { + protobuf_unittest::TestOneofParsingLite original; + original.set_oneof_int32(17); + string serialized; + EXPECT_TRUE(original.SerializeToString(&serialized)); + protobuf_unittest::TestOneofParsingLite parsed; + for (int i = 0; i < 2; ++i) { + google::protobuf::io::CodedInputStream input_stream( + reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()), + serialized.size()); + EXPECT_TRUE(parsed.MergeFromCodedStream(&input_stream)); + EXPECT_EQ(17, parsed.oneof_int32()); + } + } + + // Submessage + { + protobuf_unittest::TestOneofParsingLite original; + original.mutable_oneof_submessage()->set_optional_int32(5); + string serialized; + EXPECT_TRUE(original.SerializeToString(&serialized)); + protobuf_unittest::TestOneofParsingLite parsed; + for (int i = 0; i < 2; ++i) { + google::protobuf::io::CodedInputStream input_stream( + reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()), + serialized.size()); + EXPECT_TRUE(parsed.MergeFromCodedStream(&input_stream)); + EXPECT_EQ(5, parsed.oneof_submessage().optional_int32()); + } + } + + // String + { + protobuf_unittest::TestOneofParsingLite original; + original.set_oneof_string("string"); + string serialized; + EXPECT_TRUE(original.SerializeToString(&serialized)); + protobuf_unittest::TestOneofParsingLite parsed; + for (int i = 0; i < 2; ++i) { + google::protobuf::io::CodedInputStream input_stream( + reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()), + serialized.size()); + EXPECT_TRUE(parsed.MergeFromCodedStream(&input_stream)); + EXPECT_EQ("string", parsed.oneof_string()); + } + } + + // Bytes + { + protobuf_unittest::TestOneofParsingLite original; + original.set_oneof_bytes("bytes"); + string serialized; + EXPECT_TRUE(original.SerializeToString(&serialized)); + protobuf_unittest::TestOneofParsingLite parsed; + for (int i = 0; i < 2; ++i) { + google::protobuf::io::CodedInputStream input_stream( + reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()), + serialized.size()); + EXPECT_TRUE(parsed.MergeFromCodedStream(&input_stream)); + EXPECT_EQ("bytes", parsed.oneof_bytes()); + } + } + + // Enum + { + protobuf_unittest::TestOneofParsingLite original; + original.set_oneof_enum(protobuf_unittest::V2_SECOND); + string serialized; + EXPECT_TRUE(original.SerializeToString(&serialized)); + protobuf_unittest::TestOneofParsingLite parsed; + for (int i = 0; i < 2; ++i) { + google::protobuf::io::CodedInputStream input_stream( + reinterpret_cast<const ::google::protobuf::uint8*>(serialized.data()), + serialized.size()); + EXPECT_TRUE(parsed.MergeFromCodedStream(&input_stream)); + EXPECT_EQ(protobuf_unittest::V2_SECOND, parsed.oneof_enum()); + } + } std::cout << "PASS" << std::endl; } diff --git a/src/google/protobuf/map.h b/src/google/protobuf/map.h index 18ee3652..2d561c24 100644 --- a/src/google/protobuf/map.h +++ b/src/google/protobuf/map.h @@ -865,14 +865,7 @@ class Map { size_type BucketNumber(const Key& k) const { // We inherit from hasher, so one-arg operator() provides a hash function. size_type h = (*const_cast<InnerMap*>(this))(k); - // To help prevent people from making assumptions about the hash function, - // we use the seed differently depending on NDEBUG. The default hash - // function, the seeding, etc., are all likely to change in the future. -#ifndef NDEBUG - return (h * (seed_ | 1)) & (num_buckets_ - 1); -#else return (h + seed_) & (num_buckets_ - 1); -#endif } bool IsMatch(const Key& k0, const Key& k1) const { @@ -952,12 +945,16 @@ class Map { public: // Iterators - class const_iterator - : public std::iterator<std::forward_iterator_tag, value_type, ptrdiff_t, - const value_type*, const value_type&> { + class const_iterator { typedef typename InnerMap::const_iterator InnerIt; public: + typedef std::forward_iterator_tag iterator_category; + typedef typename Map::value_type value_type; + typedef ptrdiff_t difference_type; + typedef const value_type* pointer; + typedef const value_type& reference; + const_iterator() {} explicit const_iterator(const InnerIt& it) : it_(it) {} @@ -983,10 +980,16 @@ class Map { InnerIt it_; }; - class iterator : public std::iterator<std::forward_iterator_tag, value_type> { + class iterator { typedef typename InnerMap::iterator InnerIt; public: + typedef std::forward_iterator_tag iterator_category; + typedef typename Map::value_type value_type; + typedef ptrdiff_t difference_type; + typedef value_type* pointer; + typedef value_type& reference; + iterator() {} explicit iterator(const InnerIt& it) : it_(it) {} diff --git a/src/google/protobuf/map_entry.h b/src/google/protobuf/map_entry.h index 7c675568..7c618b82 100644 --- a/src/google/protobuf/map_entry.h +++ b/src/google/protobuf/map_entry.h @@ -98,8 +98,7 @@ class MapEntry offsets_, has_bits_, GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _has_bits_), - GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, - _internal_metadata_), + GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(MapEntry, _internal_metadata_), -1, -1, sizeof(MapEntry)}; @@ -147,6 +146,30 @@ template <typename Derived, typename Key, typename Value, uint32 MapEntry<Derived, Key, Value, kKeyFieldType, kValueFieldType, default_enum_value>::has_bits_[2] = {0, 1}; +// Specialization for the full runtime +template <typename Derived, typename Key, typename Value, + WireFormatLite::FieldType kKeyFieldType, + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +struct MapEntryHelper<MapEntry<Derived, Key, Value, kKeyFieldType, + kValueFieldType, default_enum_value> > + : MapEntryHelper<MapEntryLite<Key, Value, kKeyFieldType, kValueFieldType, + default_enum_value> > { + explicit MapEntryHelper(const MapPair<Key, Value>& map_pair) + : MapEntryHelper<MapEntryLite<Key, Value, kKeyFieldType, kValueFieldType, + default_enum_value> >(map_pair) {} +}; + +template <typename Derived, typename K, typename V, + WireFormatLite::FieldType key, WireFormatLite::FieldType value, + int default_enum> +struct DeconstructMapEntry<MapEntry<Derived, K, V, key, value, default_enum> > { + typedef K Key; + typedef V Value; + static const WireFormatLite::FieldType kKeyFieldType = key; + static const WireFormatLite::FieldType kValueFieldType = value; + static const int default_enum_value = default_enum; +}; + } // namespace internal } // namespace protobuf diff --git a/src/google/protobuf/map_entry_lite.h b/src/google/protobuf/map_entry_lite.h index c466cc7b..d245cfc7 100644 --- a/src/google/protobuf/map_entry_lite.h +++ b/src/google/protobuf/map_entry_lite.h @@ -34,6 +34,7 @@ #include <assert.h> #include <google/protobuf/arena.h> +#include <google/protobuf/map.h> #include <google/protobuf/map_type_handler.h> #include <google/protobuf/wire_format_lite_inl.h> @@ -552,6 +553,23 @@ class MapEntryLite default_enum_value>& other) { MergeFromInternal(other); } + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapEntryLite); +}; +// The completely unprincipled and unwieldy use of template parameters in +// the map code necessitates wrappers to make the code a little bit more +// manageable. +template <typename Derived> +struct DeconstructMapEntry; + +template <typename K, typename V, WireFormatLite::FieldType key, + WireFormatLite::FieldType value, int default_enum> +struct DeconstructMapEntry<MapEntryLite<K, V, key, value, default_enum> > { + typedef K Key; + typedef V Value; + static const WireFormatLite::FieldType kKeyFieldType = key; + static const WireFormatLite::FieldType kValueFieldType = value; + static const int default_enum_value = default_enum; }; // Helpers for deterministic serialization ============================= @@ -580,6 +598,75 @@ template <typename T> struct CompareByDerefFirst { } }; +// Helper for table driven serialization + +template <WireFormatLite::FieldType FieldType> +struct FromHelper { + template <typename T> + static const T& From(const T& x) { + return x; + } +}; + +template <> +struct FromHelper<WireFormatLite::TYPE_STRING> { + static ArenaStringPtr From(const string& x) { + ArenaStringPtr res; + res.UnsafeArenaSetAllocated(NULL, const_cast<string*>(&x), NULL); + return res; + } +}; +template <> +struct FromHelper<WireFormatLite::TYPE_BYTES> { + static ArenaStringPtr From(const string& x) { + ArenaStringPtr res; + res.UnsafeArenaSetAllocated(NULL, const_cast<string*>(&x), NULL); + return res; + } +}; +template <> +struct FromHelper<WireFormatLite::TYPE_MESSAGE> { + template <typename T> + static T* From(const T& x) { + return const_cast<T*>(&x); + } +}; + +template <typename MapEntryType> +struct MapEntryHelper; + +template <typename Key, typename Value, WireFormatLite::FieldType kKeyFieldType, + WireFormatLite::FieldType kValueFieldType, int default_enum_value> +struct MapEntryHelper<MapEntryLite<Key, Value, kKeyFieldType, kValueFieldType, + default_enum_value> > { + // Provide utilities to parse/serialize key/value. Provide utilities to + // manipulate internal stored type. + typedef MapTypeHandler<kKeyFieldType, Key> KeyTypeHandler; + typedef MapTypeHandler<kValueFieldType, Value> ValueTypeHandler; + + // Define internal memory layout. Strings and messages are stored as + // pointers, while other types are stored as values. + typedef typename KeyTypeHandler::TypeOnMemory KeyOnMemory; + typedef typename ValueTypeHandler::TypeOnMemory ValueOnMemory; + + explicit MapEntryHelper(const MapPair<Key, Value>& map_pair) + : _has_bits_(3), + _cached_size_(2 + KeyTypeHandler::GetCachedSize(map_pair.first) + + ValueTypeHandler::GetCachedSize(map_pair.second)), + key_(FromHelper<kKeyFieldType>::From(map_pair.first)), + value_(FromHelper<kValueFieldType>::From(map_pair.second)) {} + + // Purposely not folowing the style guide naming. These are the names + // the proto compiler would generate given the map entry descriptor. + // The proto compiler generates the offsets in this struct as if this was + // a regular message. This way the table driven code barely notices it's + // dealing with a map field. + uint32 _has_bits_; // NOLINT + uint32 _cached_size_; // NOLINT + KeyOnMemory key_; // NOLINT + ValueOnMemory value_; // NOLINT +}; + } // namespace internal } // namespace protobuf diff --git a/src/google/protobuf/map_field.h b/src/google/protobuf/map_field.h index 9d5a328e..bd478901 100644 --- a/src/google/protobuf/map_field.h +++ b/src/google/protobuf/map_field.h @@ -170,6 +170,7 @@ class LIBPROTOBUF_EXPORT MapFieldBase { // IncreaseIterator() is called by operator++() of MapIterator only. // It implements the ++ operator of MapIterator. virtual void IncreaseIterator(MapIterator* map_iter) const = 0; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapFieldBase); }; // This class provides common Map Reflection implementations for generated @@ -199,6 +200,7 @@ class TypeDefinedMapFieldBase : public MapFieldBase { void IncreaseIterator(MapIterator* map_iter) const; virtual void SetMapIteratorValue(MapIterator* map_iter) const = 0; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeDefinedMapFieldBase); }; // This class provides access to map field using generated api. It is used for @@ -231,6 +233,9 @@ class MapField : public TypeDefinedMapFieldBase<Key, T> { typedef typename MapIf<kIsValueEnum, T, const T&>::type CastValueType; public: + typedef typename Derived::SuperType EntryTypeTrait; + typedef Map<Key, T> MapType; + MapField() {} explicit MapField(Arena* arena) : TypeDefinedMapFieldBase<Key, T>(arena), impl_(arena) {} @@ -287,6 +292,15 @@ class MapField : public TypeDefinedMapFieldBase<Key, T> { friend class ::google::protobuf::Arena; friend class MapFieldStateTest; // For testing, it needs raw access to impl_ + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapField); +}; + +template <typename MEntry> +struct MapEntryToMapField { + typedef DeconstructMapEntry<typename MEntry::SuperType> T; + typedef MapField<MEntry, typename T::Key, typename T::Value, T::kKeyFieldType, + T::kValueFieldType, T::default_enum_value> + MapFieldType; }; class LIBPROTOBUF_EXPORT DynamicMapField: public TypeDefinedMapFieldBase<MapKey, MapValueRef> { @@ -314,6 +328,7 @@ class LIBPROTOBUF_EXPORT DynamicMapField: public TypeDefinedMapFieldBase<MapKey, void SyncMapWithRepeatedFieldNoLock() const; size_t SpaceUsedExcludingSelfNoLock() const; void SetMapIteratorValue(MapIterator* map_iter) const; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(DynamicMapField); }; } // namespace internal @@ -338,6 +353,10 @@ class LIBPROTOBUF_EXPORT MapKey { MapKey(const MapKey& other) : type_(0) { CopyFrom(other); } + MapKey& operator=(const MapKey& other) { + CopyFrom(other); + return *this; + } ~MapKey() { if (type_ == FieldDescriptor::CPPTYPE_STRING) { @@ -697,6 +716,7 @@ class LIBPROTOBUF_EXPORT MapValueRef { void* data_; // type_ is 0 or a valid FieldDescriptor::CppType. int type_; + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MapValueRef); }; #undef TYPE_CHECK @@ -718,6 +738,11 @@ class LIBPROTOBUF_EXPORT MapIterator { ~MapIterator() { map_->DeleteIterator(this); } + MapIterator& operator=(const MapIterator& other) { + map_ = other.map_; + map_->CopyIterator(this, other); + return *this; + } friend bool operator==(const MapIterator& a, const MapIterator& b) { return a.map_->EqualIterator(a, b); } diff --git a/src/google/protobuf/map_field_lite.h b/src/google/protobuf/map_field_lite.h index 2d102392..0ac7aeec 100644 --- a/src/google/protobuf/map_field_lite.h +++ b/src/google/protobuf/map_field_lite.h @@ -33,6 +33,7 @@ #include <google/protobuf/map.h> #include <google/protobuf/map_entry_lite.h> +#include <google/protobuf/wire_format_lite.h> namespace google { namespace protobuf { @@ -49,6 +50,9 @@ class MapFieldLite { typedef Derived EntryType; public: + typedef Map<Key, T> MapType; + typedef EntryType EntryTypeTrait; + MapFieldLite() : arena_(NULL) { SetDefaultEnumValue(); } explicit MapFieldLite(Arena* arena) : arena_(arena), map_(arena) { @@ -104,7 +108,6 @@ class MapFieldLite { friend class ::google::protobuf::Arena; }; - // True if IsInitialized() is true for value field in all elements of t. T is // expected to be message. It's useful to have this helper here to keep the // protobuf compiler from ever having to emit loops in IsInitialized() methods. diff --git a/src/google/protobuf/map_test.cc b/src/google/protobuf/map_test.cc index a06b432a..960589ce 100644 --- a/src/google/protobuf/map_test.cc +++ b/src/google/protobuf/map_test.cc @@ -236,6 +236,13 @@ TEST_F(MapImplTest, UsageErrors) { #endif // PROTOBUF_HAS_DEATH_TEST +TEST_F(MapImplTest, MapKeyAssignment) { + MapKey from, to; + from.SetStringValue("abc"); + to = from; + EXPECT_EQ("abc", to.GetStringValue()); +} + TEST_F(MapImplTest, CountNonExist) { EXPECT_EQ(0, map_.count(0)); } @@ -954,6 +961,17 @@ TEST_F(MapImplTest, SwapArena) { testing::Pair(9398, 41999))); } +TEST_F(MapImplTest, CopyAssignMapIterator) { + TestMap message; + MapReflectionTester reflection_tester( + unittest::TestMap::descriptor()); + reflection_tester.SetMapFieldsViaMapReflection(&message); + MapIterator it1 = reflection_tester.MapBegin(&message, "map_int32_int32"); + MapIterator it2 = reflection_tester.MapEnd(&message, "map_int32_int32"); + it2 = it1; + EXPECT_EQ(it1.GetKey().GetInt32Value(), it2.GetKey().GetInt32Value()); +} + // Map Field Reflection Test ======================================== static int Func(int i, int j) { diff --git a/src/google/protobuf/map_test_util.cc b/src/google/protobuf/map_test_util.cc index 4d3ad609..31ac1736 100644 --- a/src/google/protobuf/map_test_util.cc +++ b/src/google/protobuf/map_test_util.cc @@ -760,6 +760,18 @@ Message* MapReflectionTester::GetMapEntryViaReflection(Message* message, return reflection->MutableRepeatedMessage(message, F(field_name), index); } +MapIterator MapReflectionTester::MapBegin(Message* message, + const string& field_name) { + const Reflection* reflection = message->GetReflection(); + return reflection->MapBegin(message, F(field_name)); +} + +MapIterator MapReflectionTester::MapEnd(Message* message, + const string& field_name) { + const Reflection* reflection = message->GetReflection(); + return reflection->MapEnd(message, F(field_name)); +} + void MapReflectionTester::ClearMapFieldsViaReflection( Message* message) { const Reflection* reflection = message->GetReflection(); diff --git a/src/google/protobuf/map_test_util.h b/src/google/protobuf/map_test_util.h index 15c6c289..dd397619 100644 --- a/src/google/protobuf/map_test_util.h +++ b/src/google/protobuf/map_test_util.h @@ -111,6 +111,8 @@ class MapReflectionTester { const MapKey& map_key, MapValueRef* map_val); Message* GetMapEntryViaReflection(Message* message, const string& field_name, int index); + MapIterator MapBegin(Message* message, const string& field_name); + MapIterator MapEnd(Message* message, const string& field_name); private: const FieldDescriptor* F(const string& name); diff --git a/src/google/protobuf/map_type_handler.h b/src/google/protobuf/map_type_handler.h index 301b37fe..a10a7205 100644 --- a/src/google/protobuf/map_type_handler.h +++ b/src/google/protobuf/map_type_handler.h @@ -32,7 +32,6 @@ #define GOOGLE_PROTOBUF_TYPE_HANDLER_H__ #include <google/protobuf/arena.h> -#include <google/protobuf/generated_message_util.h> #include <google/protobuf/wire_format_lite_inl.h> namespace google { diff --git a/src/google/protobuf/map_unittest.proto b/src/google/protobuf/map_unittest.proto index c6154f04..836dc10b 100644 --- a/src/google/protobuf/map_unittest.proto +++ b/src/google/protobuf/map_unittest.proto @@ -60,6 +60,7 @@ message TestMap { map<int32 , MapEnum > map_int32_enum = 16; map<int32 , ForeignMessage> map_int32_foreign_message = 17; map<string , ForeignMessage> map_string_foreign_message = 18; + map<int32 , TestAllTypes> map_int32_all_types = 19; } message TestMapSubmessage { diff --git a/src/google/protobuf/message.cc b/src/google/protobuf/message.cc index 2134f95f..c01d1974 100644 --- a/src/google/protobuf/message.cc +++ b/src/google/protobuf/message.cc @@ -143,7 +143,13 @@ bool Message::ParsePartialFromIstream(std::istream* input) { void Message::SerializeWithCachedSizes( io::CodedOutputStream* output) const { - WireFormat::SerializeWithCachedSizes(*this, GetCachedSize(), output); + const internal::SerializationTable* table = + static_cast<const internal::SerializationTable*>(InternalGetTable()); + if (table == 0) { + WireFormat::SerializeWithCachedSizes(*this, GetCachedSize(), output); + } else { + internal::TableSerialize(*this, table, output); + } } size_t Message::ByteSizeLong() const { @@ -191,6 +197,10 @@ bool Message::SerializePartialToOstream(std::ostream* output) const { Reflection::~Reflection() {} +void Reflection::AddAllocatedMessage(Message* /* message */, + const FieldDescriptor* /*field */, + Message* /* new_entry */) const {} + #define HANDLE_TYPE(TYPE, CPPTYPE, CTYPE) \ template<> \ const RepeatedField<TYPE>& Reflection::GetRepeatedField<TYPE>( \ diff --git a/src/google/protobuf/message.h b/src/google/protobuf/message.h index 68acb5b1..c65ff625 100644 --- a/src/google/protobuf/message.h +++ b/src/google/protobuf/message.h @@ -254,6 +254,7 @@ class LIBPROTOBUF_EXPORT Message : public MessageLite { // fields defined for the proto. virtual size_t SpaceUsedLong() const; + PROTOBUF_RUNTIME_DEPRECATED("Please use SpaceUsedLong() instead") int SpaceUsed() const { return internal::ToIntSize(SpaceUsedLong()); } // Debugging & Testing---------------------------------------------- @@ -428,6 +429,7 @@ class LIBPROTOBUF_EXPORT Reflection { // Estimate the amount of memory used by the message object. virtual size_t SpaceUsedLong(const Message& message) const = 0; + PROTOBUF_RUNTIME_DEPRECATED("Please use SpaceUsedLong() instead") int SpaceUsed(const Message& message) const { return internal::ToIntSize(SpaceUsedLong(message)); } @@ -752,9 +754,9 @@ class LIBPROTOBUF_EXPORT Reflection { // specifyed by 'field' passing ownership to the message. // TODO(tmarek): Make virtual after all subclasses have been // updated. - virtual void AddAllocatedMessage(Message* /* message */, - const FieldDescriptor* /*field */, - Message* /* new_entry */) const {} + virtual void AddAllocatedMessage(Message* message, + const FieldDescriptor* field, + Message* new_entry) const; // Get a RepeatedFieldRef object that can be used to read the underlying diff --git a/src/google/protobuf/message_lite.cc b/src/google/protobuf/message_lite.cc index fda84b51..83a92d5a 100644 --- a/src/google/protobuf/message_lite.cc +++ b/src/google/protobuf/message_lite.cc @@ -227,19 +227,6 @@ uint8* MessageLite::SerializeWithCachedSizesToArray(uint8* target) const { io::CodedOutputStream::IsDefaultSerializationDeterministic(), target); } -uint8* MessageLite::InternalSerializeWithCachedSizesToArray( - bool deterministic, uint8* target) const { - // We only optimize this when using optimize_for = SPEED. In other cases - // we just use the CodedOutputStream path. - int size = GetCachedSize(); - io::ArrayOutputStream out(target, size); - io::CodedOutputStream coded_out(&out); - coded_out.SetSerializationDeterministic(deterministic); - SerializeWithCachedSizes(&coded_out); - GOOGLE_CHECK(!coded_out.HadError()); - return target + size; -} - bool MessageLite::SerializeToCodedStream(io::CodedOutputStream* output) const { GOOGLE_DCHECK(IsInitialized()) << InitializationErrorMessage("serialize", *this); return SerializePartialToCodedStream(output); @@ -357,6 +344,36 @@ string MessageLite::SerializePartialAsString() const { return output; } +void MessageLite::SerializeWithCachedSizes(io::CodedOutputStream* output) const + { + GOOGLE_DCHECK(InternalGetTable()); + internal::TableSerialize(*this, static_cast<const internal::SerializationTable*>(InternalGetTable()), output); +} + +// The table driven code optimizes the case that the CodedOutputStream buffer +// is large enough to serialize into it directly. +// If the proto is optimized for speed, this method will be overridden by +// generated code for maximum speed. If the proto is optimized for size or +// is lite, then we need to specialize this to avoid infinite recursion. +uint8* MessageLite::InternalSerializeWithCachedSizesToArray(bool deterministic, + uint8* target) const { + const internal::SerializationTable* table = + static_cast<const internal::SerializationTable*>(InternalGetTable()); + if (table == NULL) { + // We only optimize this when using optimize_for = SPEED. In other cases + // we just use the CodedOutputStream path. + int size = GetCachedSize(); + io::ArrayOutputStream out(target, size); + io::CodedOutputStream coded_out(&out); + coded_out.SetSerializationDeterministic(deterministic); + SerializeWithCachedSizes(&coded_out); + GOOGLE_CHECK(!coded_out.HadError()); + return target + size; + } else { + return internal::TableSerializeToArray(*this, table, deterministic, target); + } +} + namespace internal { template<> MessageLite* GenericTypeHandler<MessageLite>::NewFromPrototype( @@ -373,6 +390,13 @@ void GenericTypeHandler<string>::Merge(const string& from, string* to) { *to = from; } + +bool proto3_preserve_unknown_ = false; +void SetProto3PreserveUnknownsDefault(bool preserve) { + proto3_preserve_unknown_ = preserve; +} + + } // namespace internal } // namespace protobuf diff --git a/src/google/protobuf/message_lite.h b/src/google/protobuf/message_lite.h index 046a736d..2075f4b6 100644 --- a/src/google/protobuf/message_lite.h +++ b/src/google/protobuf/message_lite.h @@ -42,22 +42,130 @@ #include <climits> #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/logging.h> -#include <google/protobuf/generated_message_util.h> +#include <google/protobuf/stubs/once.h> +#if LANG_CXX11 && !defined(__NVCC__) +#define PROTOBUF_CXX11 1 +#else +#define PROTOBUF_CXX11 0 +#endif + +#if PROTOBUF_CXX11 +#define PROTOBUF_FINAL final +#else +#define PROTOBUF_FINAL +#endif + +#ifndef LIBPROTOBUF_EXPORT +#define LIBPROTOBUF_EXPORT +#endif + +#define PROTOBUF_RUNTIME_DEPRECATED(message) + namespace google { namespace protobuf { - class Arena; +class Arena; namespace io { - class CodedInputStream; - class CodedOutputStream; - class ZeroCopyInputStream; - class ZeroCopyOutputStream; +class CodedInputStream; +class CodedOutputStream; +class ZeroCopyInputStream; +class ZeroCopyOutputStream; } namespace internal { - class WireFormatLite; + +class WireFormatLite; + +#ifndef SWIG +// We compute sizes as size_t but cache them as int. This function converts a +// computed size to a cached size. Since we don't proceed with serialization +// if the total size was > INT_MAX, it is not important what this function +// returns for inputs > INT_MAX. However this case should not error or +// GOOGLE_CHECK-fail, because the full size_t resolution is still returned from +// ByteSizeLong() and checked against INT_MAX; we can catch the overflow +// there. +inline int ToCachedSize(size_t size) { return static_cast<int>(size); } + +// We mainly calculate sizes in terms of size_t, but some functions that +// compute sizes return "int". These int sizes are expected to always be +// positive. This function is more efficient than casting an int to size_t +// directly on 64-bit platforms because it avoids making the compiler emit a +// sign extending instruction, which we don't want and don't want to pay for. +inline size_t FromIntSize(int size) { + // Convert to unsigned before widening so sign extension is not necessary. + return static_cast<unsigned int>(size); +} + +// For cases where a legacy function returns an integer size. We GOOGLE_DCHECK() +// that the conversion will fit within an integer; if this is false then we +// are losing information. +inline int ToIntSize(size_t size) { + GOOGLE_DCHECK_LE(size, static_cast<size_t>(INT_MAX)); + return static_cast<int>(size); } +// This type wraps a variable whose constructor and destructor are explicitly +// called. It is particularly useful for a global variable, without its +// constructor and destructor run on start and end of the program lifetime. +// This circumvents the initial construction order fiasco, while keeping +// the address of the empty string a compile time constant. +// +// Pay special attention to the initialization state of the object. +// 1. The object is "uninitialized" to begin with. +// 2. Call DefaultConstruct() only if the object is uninitialized. +// After the call, the object becomes "initialized". +// 3. Call get() and get_mutable() only if the object is initialized. +// 4. Call Destruct() only if the object is initialized. +// After the call, the object becomes uninitialized. +template <typename T> +class ExplicitlyConstructed { + public: + void DefaultConstruct() { + new (&union_) T(); + } + + void Destruct() { + get_mutable()->~T(); + } + +#if LANG_CXX11 + constexpr +#endif + const T& + get() const { + return reinterpret_cast<const T&>(union_); + } + T* get_mutable() { return reinterpret_cast<T*>(&union_); } + + private: + // Prefer c++14 aligned_storage, but for compatibility this will do. + union AlignedUnion { + char space[sizeof(T)]; + int64 align_to_int64; + void* align_to_ptr; + } union_; +}; + +// Default empty string object. Don't use this directly. Instead, call +// GetEmptyString() to get the reference. +extern ExplicitlyConstructed< ::std::string> fixed_address_empty_string; +LIBPROTOBUF_EXPORT extern ProtobufOnceType empty_string_once_init_; +LIBPROTOBUF_EXPORT void InitEmptyString(); + + +LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyStringAlreadyInited() { + return fixed_address_empty_string.get(); +} + +LIBPROTOBUF_EXPORT inline const ::std::string& GetEmptyString() { + ::google::protobuf::GoogleOnceInit(&empty_string_once_init_, &InitEmptyString); + return GetEmptyStringAlreadyInited(); +} + +LIBPROTOBUF_EXPORT size_t StringSpaceUsedExcludingSelfLong(const string& str); +#endif // SWIG +} // namespace internal + // Interface to light weight protocol messages. // // This interface is implemented by all protocol message objects. Non-lite @@ -102,18 +210,19 @@ class LIBPROTOBUF_EXPORT MessageLite { // Get the arena, if any, associated with this message. Virtual method // required for generic operations but most arena-related operations should // use the GetArenaNoVirtual() generated-code method. Default implementation - // to reduce code size by avoiding the need for per-type implementations when - // types do not implement arena support. + // to reduce code size by avoiding the need for per-type implementations + // when types do not implement arena support. virtual ::google::protobuf::Arena* GetArena() const { return NULL; } - // Get a pointer that may be equal to this message's arena, or may not be. If - // the value returned by this method is equal to some arena pointer, then this - // message is on that arena; however, if this message is on some arena, this - // method may or may not return that arena's pointer. As a tradeoff, this - // method may be more efficient than GetArena(). The intent is to allow - // underlying representations that use e.g. tagged pointers to sometimes store - // the arena pointer directly, and sometimes in a more indirect way, and allow - // a fastpath comparison against the arena pointer when it's easy to obtain. + // Get a pointer that may be equal to this message's arena, or may not be. + // If the value returned by this method is equal to some arena pointer, then + // this message is on that arena; however, if this message is on some arena, + // this method may or may not return that arena's pointer. As a tradeoff, + // this method may be more efficient than GetArena(). The intent is to allow + // underlying representations that use e.g. tagged pointers to sometimes + // store the arena pointer directly, and sometimes in a more indirect way, + // and allow a fastpath comparison against the arena pointer when it's easy + // to obtain. virtual void* GetMaybeArenaPointer() const { return GetArena(); } // Clear all fields of the message and set them to their default values. @@ -131,19 +240,20 @@ class LIBPROTOBUF_EXPORT MessageLite { // for full messages. See message.h. virtual string InitializationErrorString() const; - // If |other| is the exact same class as this, calls MergeFrom(). Otherwise, + // If |other| is the exact same class as this, calls MergeFrom(). Otherwise, // results are undefined (probably crash). virtual void CheckTypeAndMergeFrom(const MessageLite& other) = 0; // Parsing --------------------------------------------------------- // Methods for parsing in protocol buffer format. Most of these are - // just simple wrappers around MergeFromCodedStream(). Clear() will be called - // before merging the input. - - // Fill the message with a protocol buffer parsed from the given input stream. - // Returns false on a read error or if the input is in the wrong format. A - // successful return does not indicate the entire input is consumed, ensure - // you call ConsumedEntireMessage() to check that if applicable. + // just simple wrappers around MergeFromCodedStream(). Clear() will be + // called before merging the input. + + // Fill the message with a protocol buffer parsed from the given input + // stream. Returns false on a read error or if the input is in the wrong + // format. A successful return does not indicate the entire input is + // consumed, ensure you call ConsumedEntireMessage() to check that if + // applicable. bool ParseFromCodedStream(io::CodedInputStream* input); // Like ParseFromCodedStream(), but accepts messages that are missing // required fields. @@ -249,13 +359,16 @@ class LIBPROTOBUF_EXPORT MessageLite { virtual size_t ByteSizeLong() const = 0; // Legacy ByteSize() API. - int ByteSize() const { return internal::ToIntSize(ByteSizeLong()); } + PROTOBUF_RUNTIME_DEPRECATED("Please use ByteSizeLong() instead") + int ByteSize() const { + return internal::ToIntSize(ByteSizeLong()); + } // Serializes the message without recomputing the size. The message must not // have changed since the last call to ByteSize(), and the value returned by // ByteSize must be non-negative. Otherwise the results are undefined. virtual void SerializeWithCachedSizes( - io::CodedOutputStream* output) const = 0; + io::CodedOutputStream* output) const; // Functions below here are not part of the public interface. It isn't // enforced, but they should be treated as private, and will be private @@ -286,11 +399,31 @@ class LIBPROTOBUF_EXPORT MessageLite { uint8* target) const; private: + // TODO(gerbens) make this a pure abstract function + virtual const void* InternalGetTable() const { return NULL; } + friend class internal::WireFormatLite; + friend class Message; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MessageLite); }; +namespace internal { + +extern bool LIBPROTOBUF_EXPORT proto3_preserve_unknown_; + +// DO NOT USE: For migration only. Will be removed when Proto3 defaults to +// preserve unknowns. +inline bool GetProto3PreserveUnknownsDefault() { + return proto3_preserve_unknown_; +} + +// DO NOT USE: For migration only. Will be removed when Proto3 defaults to +// preserve unknowns. +void LIBPROTOBUF_EXPORT SetProto3PreserveUnknownsDefault(bool preserve); +} // namespace internal + + } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/message_unittest.cc b/src/google/protobuf/message_unittest.cc index 0469f4ca..98d9d1fc 100644 --- a/src/google/protobuf/message_unittest.cc +++ b/src/google/protobuf/message_unittest.cc @@ -51,6 +51,7 @@ #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/io/zero_copy_stream_impl.h> #include <google/protobuf/descriptor.pb.h> +#include <google/protobuf/arena.h> #include <google/protobuf/descriptor.h> #include <google/protobuf/generated_message_reflection.h> @@ -112,8 +113,9 @@ TEST(MessageTest, ParseFromFileDescriptor) { string filename = TestSourceDir() + "/google/protobuf/testdata/golden_message"; int file = open(filename.c_str(), O_RDONLY | O_BINARY); + ASSERT_GE(file, 0); - unittest::TestAllTypes message; + protobuf_unittest::TestAllTypes message; EXPECT_TRUE(message.ParseFromFileDescriptor(file)); TestUtil::ExpectAllFieldsSet(message); @@ -125,8 +127,9 @@ TEST(MessageTest, ParsePackedFromFileDescriptor) { TestSourceDir() + "/google/protobuf/testdata/golden_packed_fields_message"; int file = open(filename.c_str(), O_RDONLY | O_BINARY); + ASSERT_GE(file, 0); - unittest::TestPackedTypes message; + protobuf_unittest::TestPackedTypes message; EXPECT_TRUE(message.ParseFromFileDescriptor(file)); TestUtil::ExpectPackedFieldsSet(message); @@ -267,6 +270,8 @@ TEST(MessageTest, CheckOverflow) { } TEST(MessageTest, CheckBigOverflow) { + // Checking for 4GB buffers on 32 bit systems is problematic. + if (sizeof(void*) < 8) return; unittest::TestAllTypes message; // Create a message with size just over 4GB. We should be able to detect this // too, even though it will make a plain "int" wrap back to a positive number. @@ -422,6 +427,18 @@ TEST(MessageTest, MessageIsStillValidAfterParseFails) { EXPECT_FALSE(message.ParseFromString(invalid_data)); message.Clear(); EXPECT_EQ(0, message.optional_uint64()); + + // invalid data for field "optional_string". Length prefix is 1 but no + // payload. + string invalid_string_data = "\x72\x01"; + { + google::protobuf::Arena arena; + unittest::TestAllTypes* arena_message = + google::protobuf::Arena::CreateMessage<unittest::TestAllTypes>(&arena); + EXPECT_FALSE(arena_message->ParseFromString(invalid_string_data)); + arena_message->Clear(); + EXPECT_EQ("", arena_message->optional_string()); + } } namespace { diff --git a/src/google/protobuf/proto3_arena_unittest.cc b/src/google/protobuf/proto3_arena_unittest.cc index 2838e0fc..3a0fb804 100644 --- a/src/google/protobuf/proto3_arena_unittest.cc +++ b/src/google/protobuf/proto3_arena_unittest.cc @@ -129,7 +129,8 @@ TEST(Proto3ArenaTest, Parsing) { ExpectAllFieldsSet(*arena_message); } -TEST(Proto3ArenaTest, UnknownFields) { +TEST(Proto3ArenaTest, UnknownFieldsDefaultDrop) { + ::google::protobuf::internal::SetProto3PreserveUnknownsDefault(false); TestAllTypes original; SetAllFields(&original); @@ -150,6 +151,28 @@ TEST(Proto3ArenaTest, UnknownFields) { arena_message->GetReflection()->GetUnknownFields(*arena_message).empty()); } +TEST(Proto3ArenaTest, UnknownFieldsDefaultPreserve) { + ::google::protobuf::internal::SetProto3PreserveUnknownsDefault(true); + TestAllTypes original; + SetAllFields(&original); + + Arena arena; + TestAllTypes* arena_message = Arena::CreateMessage<TestAllTypes>(&arena); + arena_message->ParseFromString(original.SerializeAsString()); + ExpectAllFieldsSet(*arena_message); + + // In proto3 we can still get a pointer to the UnknownFieldSet through + // reflection API. + UnknownFieldSet* unknown_fields = + arena_message->GetReflection()->MutableUnknownFields(arena_message); + // We can modify this UnknownFieldSet. + unknown_fields->AddVarint(1, 2); + // And the unknown fields should be changed. + ASSERT_NE(original.ByteSize(), arena_message->ByteSize()); + ASSERT_FALSE( + arena_message->GetReflection()->GetUnknownFields(*arena_message).empty()); +} + TEST(Proto3ArenaTest, Swap) { Arena arena1; Arena arena2; diff --git a/src/google/protobuf/repeated_field.h b/src/google/protobuf/repeated_field.h index a1013f63..20743fa9 100644 --- a/src/google/protobuf/repeated_field.h +++ b/src/google/protobuf/repeated_field.h @@ -59,7 +59,6 @@ #include <google/protobuf/stubs/common.h> #include <google/protobuf/stubs/type_traits.h> #include <google/protobuf/arena.h> -#include <google/protobuf/generated_message_util.h> #include <google/protobuf/message_lite.h> @@ -281,9 +280,6 @@ class RepeatedField PROTOBUF_FINAL { friend class Arena; typedef void InternalArenaConstructable_; - // Move the contents of |from| into |to|, possibly clobbering |from| in the - // process. For primitive types this is just a memcpy(), but it could be - // specialized for non-primitive types to, say, swap each element instead. void MoveArray(Element* to, Element* from, int size); // Copy the elements of |from| into |to|. @@ -597,6 +593,7 @@ class LIBPROTOBUF_EXPORT RepeatedPtrFieldBase { // Reserve() and MergeFrom() to reduce code size. |extend_amount| must be > 0. void** InternalExtend(int extend_amount); + friend class AccessorHelper; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(RepeatedPtrFieldBase); }; @@ -609,8 +606,7 @@ class GenericTypeHandler { #endif static inline GenericType* New(Arena* arena) { - return ::google::protobuf::Arena::CreateMaybeMessage<Type>( - arena, static_cast<GenericType*>(0)); + return ::google::protobuf::Arena::CreateMaybeMessage<Type>(arena); } static inline GenericType* NewFromPrototype( const GenericType* prototype, ::google::protobuf::Arena* arena = NULL); @@ -2449,6 +2445,12 @@ template<typename T> class RepeatedPtrFieldBackInsertIterator *field_->Add() = *ptr_to_value; return *this; } +#if LANG_CXX11 + RepeatedPtrFieldBackInsertIterator<T>& operator=(T&& value) { + *field_->Add() = std::move(value); + return *this; + } +#endif RepeatedPtrFieldBackInsertIterator<T>& operator*() { return *this; } diff --git a/src/google/protobuf/repeated_field_unittest.cc b/src/google/protobuf/repeated_field_unittest.cc index 043cc746..ae501465 100644 --- a/src/google/protobuf/repeated_field_unittest.cc +++ b/src/google/protobuf/repeated_field_unittest.cc @@ -1586,6 +1586,38 @@ TEST_F(RepeatedFieldInsertionIteratorsTest, EXPECT_EQ(testproto.DebugString(), goldenproto.DebugString()); } +#if LANG_CXX11 +TEST_F(RepeatedFieldInsertionIteratorsTest, MoveStrings) { + std::vector<string> src = {"a", "b", "c", "d"}; + std::vector<string> copy = src; // copy since move leaves in undefined state + TestAllTypes testproto; + std::move(copy.begin(), copy.end(), + RepeatedFieldBackInserter(testproto.mutable_repeated_string())); + + ASSERT_THAT(testproto.repeated_string(), testing::ElementsAreArray(src)); +} + +TEST_F(RepeatedFieldInsertionIteratorsTest, MoveProtos) { + auto make_nested = [](int32 x) { + Nested ret; + ret.set_bb(x); + return ret; + }; + std::vector<Nested> src = {make_nested(3), make_nested(5), make_nested(7)}; + std::vector<Nested> copy = src; // copy since move leaves in undefined state + TestAllTypes testproto; + std::move( + copy.begin(), copy.end(), + RepeatedFieldBackInserter(testproto.mutable_repeated_nested_message())); + + ASSERT_EQ(src.size(), testproto.repeated_nested_message_size()); + for (int i = 0; i < src.size(); ++i) { + EXPECT_EQ(src[i].DebugString(), + testproto.repeated_nested_message(i).DebugString()); + } +} +#endif + } // namespace } // namespace protobuf diff --git a/src/google/protobuf/source_context.pb.cc b/src/google/protobuf/source_context.pb.cc index 3244444a..3a7c5b50 100644 --- a/src/google/protobuf/source_context.pb.cc +++ b/src/google/protobuf/source_context.pb.cc @@ -32,20 +32,20 @@ namespace { } // namespace PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField - const TableStruct::entries[] = { + const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField - const TableStruct::aux[] = { + const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ::google::protobuf::internal::AuxillaryParseTableField(), }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const - TableStruct::schema[] = { + TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { NULL, NULL, 0, -1, -1, false }, }; -const ::google::protobuf::uint32 TableStruct::offsets[] = { +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceContext, _internal_metadata_), ~0u, // no _extensions_ @@ -53,8 +53,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(SourceContext, file_name_), }; - -static const ::google::protobuf::internal::MigrationSchema schemas[] = { +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { 0, -1, sizeof(SourceContext)}, }; @@ -84,12 +83,6 @@ void protobuf_RegisterTypes(const ::std::string&) { } } // namespace - -void TableStruct::Shutdown() { - _SourceContext_default_instance_.Shutdown(); - delete file_level_metadata[0].reflection; -} - void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -103,7 +96,7 @@ void InitDefaults() { } void AddDescriptorsImpl() { InitDefaults(); - static const char descriptor[] = { + static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { "\n$google/protobuf/source_context.proto\022\017" "google.protobuf\"\"\n\rSourceContext\022\021\n\tfile" "_name\030\001 \001(\tB\225\001\n\023com.google.protobufB\022Sou" @@ -116,14 +109,13 @@ void AddDescriptorsImpl() { descriptor, 251); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/source_context.proto", &protobuf_RegisterTypes); - ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); } void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -198,7 +190,12 @@ SourceContext* SourceContext::New(::google::protobuf::Arena* arena) const { void SourceContext::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.SourceContext) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + file_name_.ClearToEmptyNoArena(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + _internal_metadata_.Clear(); } bool SourceContext::MergePartialFromCodedStream( @@ -214,7 +211,7 @@ bool SourceContext::MergePartialFromCodedStream( // string file_name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_file_name())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -229,12 +226,11 @@ bool SourceContext::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -264,6 +260,10 @@ void SourceContext::SerializeWithCachedSizes( 1, this->file_name(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.SourceContext) } @@ -284,6 +284,10 @@ void SourceContext::SerializeWithCachedSizes( 1, this->file_name(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.SourceContext) return target; } @@ -292,6 +296,11 @@ size_t SourceContext::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.SourceContext) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // string file_name = 1; if (this->file_name().size() > 0) { total_size += 1 + @@ -357,8 +366,10 @@ void SourceContext::Swap(SourceContext* other) { InternalSwap(other); } void SourceContext::InternalSwap(SourceContext* other) { + using std::swap; file_name_.Swap(&other->file_name_); - std::swap(_cached_size_, other->_cached_size_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata SourceContext::GetMetadata() const { diff --git a/src/google/protobuf/source_context.pb.h b/src/google/protobuf/source_context.pb.h index 23cd7f3e..c9cc8b10 100644 --- a/src/google/protobuf/source_context.pb.h +++ b/src/google/protobuf/source_context.pb.h @@ -48,8 +48,9 @@ struct LIBPROTOBUF_EXPORT TableStruct { static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; static void InitDefaultsImpl(); - static void Shutdown(); }; void LIBPROTOBUF_EXPORT AddDescriptors(); void LIBPROTOBUF_EXPORT InitDefaults(); @@ -68,7 +69,21 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @ CopyFrom(from); return *this; } + #if LANG_CXX11 + SourceContext(SourceContext&& from) noexcept + : SourceContext() { + *this = ::std::move(from); + } + inline SourceContext& operator=(SourceContext&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif static const ::google::protobuf::Descriptor* descriptor(); static const SourceContext& default_instance(); @@ -80,6 +95,9 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @ 0; void Swap(SourceContext* other); + friend void swap(SourceContext& a, SourceContext& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -149,6 +167,10 @@ class LIBPROTOBUF_EXPORT SourceContext : public ::google::protobuf::Message /* @ // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ // SourceContext // string file_name = 1; @@ -204,6 +226,9 @@ inline void SourceContext::set_allocated_file_name(::std::string* file_name) { // @@protoc_insertion_point(field_set_allocated:google.protobuf.SourceContext.file_name) } +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // @@protoc_insertion_point(namespace_scope) diff --git a/src/google/protobuf/struct.pb.cc b/src/google/protobuf/struct.pb.cc index 207e9efe..bb33a553 100644 --- a/src/google/protobuf/struct.pb.cc +++ b/src/google/protobuf/struct.pb.cc @@ -46,23 +46,23 @@ const ::google::protobuf::EnumDescriptor* file_level_enum_descriptors[1]; } // namespace PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField - const TableStruct::entries[] = { + const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField - const TableStruct::aux[] = { + const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ::google::protobuf::internal::AuxillaryParseTableField(), }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const - TableStruct::schema[] = { + TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, }; -const ::google::protobuf::uint32 TableStruct::offsets[] = { +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Struct, _internal_metadata_), ~0u, // no _extensions_ @@ -74,12 +74,12 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _extensions_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, _oneof_case_[0]), ~0u, // no _weak_field_map_ - GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), null_value_), - GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), number_value_), - GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), string_value_), - GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), bool_value_), - GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), struct_value_), - GOOGLE_PROTOBUF_GENERATED_DEFAULT_ONEOF_FIELD_OFFSET((&_Value_default_instance_), list_value_), + offsetof(ValueDefaultTypeInternal, null_value_), + offsetof(ValueDefaultTypeInternal, number_value_), + offsetof(ValueDefaultTypeInternal, string_value_), + offsetof(ValueDefaultTypeInternal, bool_value_), + offsetof(ValueDefaultTypeInternal, struct_value_), + offsetof(ValueDefaultTypeInternal, list_value_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Value, kind_), ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ListValue, _internal_metadata_), @@ -88,8 +88,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(ListValue, values_), }; - -static const ::google::protobuf::internal::MigrationSchema schemas[] = { +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { 0, -1, sizeof(Struct)}, { 6, -1, sizeof(Value)}, { 18, -1, sizeof(ListValue)}, @@ -125,17 +124,6 @@ void protobuf_RegisterTypes(const ::std::string&) { } } // namespace - -void TableStruct::Shutdown() { - _Struct_default_instance_.Shutdown(); - delete file_level_metadata[1].reflection; - _Value_default_instance_.Shutdown(); - delete file_level_metadata[2].reflection; - _ListValue_default_instance_.Shutdown(); - delete file_level_metadata[3].reflection; - delete file_level_metadata[0].reflection; -} - void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -163,7 +151,7 @@ void InitDefaults() { } void AddDescriptorsImpl() { InitDefaults(); - static const char descriptor[] = { + static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { "\n\034google/protobuf/struct.proto\022\017google.p" "rotobuf\"\204\001\n\006Struct\0223\n\006fields\030\001 \003(\0132#.goo" "gle.protobuf.Struct.FieldsEntry\032E\n\013Field" @@ -186,14 +174,13 @@ void AddDescriptorsImpl() { descriptor, 641); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/struct.proto", &protobuf_RegisterTypes); - ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); } void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -253,9 +240,7 @@ Struct::Struct(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena), fields_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Struct) @@ -280,6 +265,7 @@ Struct::~Struct() { void Struct::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -313,7 +299,12 @@ Struct* Struct::New(::google::protobuf::Arena* arena) const { void Struct::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Struct) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + fields_.Clear(); + _internal_metadata_.Clear(); } bool Struct::MergePartialFromCodedStream( @@ -329,7 +320,7 @@ bool Struct::MergePartialFromCodedStream( // map<string, .google.protobuf.Value> fields = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { Struct_FieldsEntry::Parser< ::google::protobuf::internal::MapField< Struct_FieldsEntry, ::std::string, ::google::protobuf::Value, @@ -351,12 +342,11 @@ bool Struct::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -431,6 +421,10 @@ void Struct::SerializeWithCachedSizes( } } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Struct) } @@ -499,6 +493,10 @@ void Struct::SerializeWithCachedSizes( } } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Struct) return target; } @@ -507,6 +505,11 @@ size_t Struct::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Struct) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // map<string, .google.protobuf.Value> fields = 1; total_size += 1 * ::google::protobuf::internal::FromIntSize(this->fields_size()); @@ -597,8 +600,10 @@ void Struct::UnsafeArenaSwap(Struct* other) { InternalSwap(other); } void Struct::InternalSwap(Struct* other) { + using std::swap; fields_.Swap(&other->fields_); - std::swap(_cached_size_, other->_cached_size_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Struct::GetMetadata() const { @@ -651,9 +656,7 @@ Value::Value() Value::Value(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Value) @@ -708,6 +711,7 @@ Value::~Value() { void Value::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -784,7 +788,12 @@ void Value::clear_kind() { void Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Value) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + clear_kind(); + _internal_metadata_.Clear(); } bool Value::MergePartialFromCodedStream( @@ -800,7 +809,7 @@ bool Value::MergePartialFromCodedStream( // .google.protobuf.NullValue null_value = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -815,7 +824,7 @@ bool Value::MergePartialFromCodedStream( // double number_value = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(17u)) { + static_cast< ::google::protobuf::uint8>(17u /* 17 & 0xFF */)) { clear_kind(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< double, ::google::protobuf::internal::WireFormatLite::TYPE_DOUBLE>( @@ -830,7 +839,7 @@ bool Value::MergePartialFromCodedStream( // string string_value = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_string_value())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -846,7 +855,7 @@ bool Value::MergePartialFromCodedStream( // bool bool_value = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(32u)) { + static_cast< ::google::protobuf::uint8>(32u /* 32 & 0xFF */)) { clear_kind(); DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -861,7 +870,7 @@ bool Value::MergePartialFromCodedStream( // .google.protobuf.Struct struct_value = 5; case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(42u)) { + static_cast< ::google::protobuf::uint8>(42u /* 42 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_struct_value())); } else { @@ -873,7 +882,7 @@ bool Value::MergePartialFromCodedStream( // .google.protobuf.ListValue list_value = 6; case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(50u)) { + static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_list_value())); } else { @@ -884,12 +893,11 @@ bool Value::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -947,6 +955,10 @@ void Value::SerializeWithCachedSizes( 6, *kind_.list_value_, output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Value) } @@ -997,6 +1009,10 @@ void Value::SerializeWithCachedSizes( 6, *kind_.list_value_, deterministic, target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Value) return target; } @@ -1005,6 +1021,11 @@ size_t Value::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Value) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } switch (kind_case()) { // .google.protobuf.NullValue null_value = 1; case kNullValue: { @@ -1145,9 +1166,11 @@ void Value::UnsafeArenaSwap(Value* other) { InternalSwap(other); } void Value::InternalSwap(Value* other) { - std::swap(kind_, other->kind_); - std::swap(_oneof_case_[0], other->_oneof_case_[0]); - std::swap(_cached_size_, other->_cached_size_); + using std::swap; + swap(kind_, other->kind_); + swap(_oneof_case_[0], other->_oneof_case_[0]); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Value::GetMetadata() const { @@ -1247,6 +1270,19 @@ void Value::set_string_value(const ::std::string& value) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Value.string_value) } +#if LANG_CXX11 +void Value::set_string_value(::std::string&& value) { + // @@protoc_insertion_point(field_set:google.protobuf.Value.string_value) + if (!has_string_value()) { + clear_kind(); + set_has_string_value(); + kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + } + kind_.string_value_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Value.string_value) +} +#endif void Value::set_string_value(const char* value) { GOOGLE_DCHECK(value != NULL); if (!has_string_value()) { @@ -1560,9 +1596,7 @@ ListValue::ListValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena), values_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fstruct_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.ListValue) @@ -1587,6 +1621,7 @@ ListValue::~ListValue() { void ListValue::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -1620,7 +1655,12 @@ ListValue* ListValue::New(::google::protobuf::Arena* arena) const { void ListValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.ListValue) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + values_.Clear(); + _internal_metadata_.Clear(); } bool ListValue::MergePartialFromCodedStream( @@ -1636,7 +1676,7 @@ bool ListValue::MergePartialFromCodedStream( // repeated .google.protobuf.Value values = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_values())); } else { @@ -1647,12 +1687,11 @@ bool ListValue::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -1678,6 +1717,10 @@ void ListValue::SerializeWithCachedSizes( 1, this->values(i), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.ListValue) } @@ -1694,6 +1737,10 @@ void ListValue::SerializeWithCachedSizes( 1, this->values(i), deterministic, target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.ListValue) return target; } @@ -1702,6 +1749,11 @@ size_t ListValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.ListValue) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // repeated .google.protobuf.Value values = 1; { unsigned int count = this->values_size(); @@ -1783,8 +1835,10 @@ void ListValue::UnsafeArenaSwap(ListValue* other) { InternalSwap(other); } void ListValue::InternalSwap(ListValue* other) { + using std::swap; values_.InternalSwap(&other->values_); - std::swap(_cached_size_, other->_cached_size_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata ListValue::GetMetadata() const { diff --git a/src/google/protobuf/struct.pb.h b/src/google/protobuf/struct.pb.h index a37a5652..8a9ec530 100644 --- a/src/google/protobuf/struct.pb.h +++ b/src/google/protobuf/struct.pb.h @@ -29,6 +29,7 @@ #include <google/protobuf/repeated_field.h> // IWYU pragma: export #include <google/protobuf/extension_set.h> // IWYU pragma: export #include <google/protobuf/map.h> // IWYU pragma: export +#include <google/protobuf/map_entry.h> #include <google/protobuf/map_field_inl.h> #include <google/protobuf/generated_enum_reflection.h> #include <google/protobuf/unknown_field_set.h> @@ -60,8 +61,9 @@ struct LIBPROTOBUF_EXPORT TableStruct { static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; static void InitDefaultsImpl(); - static void Shutdown(); }; void LIBPROTOBUF_EXPORT AddDescriptors(); void LIBPROTOBUF_EXPORT InitDefaults(); @@ -103,7 +105,21 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc CopyFrom(from); return *this; } + #if LANG_CXX11 + Struct(Struct&& from) noexcept + : Struct() { + *this = ::std::move(from); + } + inline Struct& operator=(Struct&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -122,6 +138,9 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc void UnsafeArenaSwap(Struct* other); void Swap(Struct* other); + friend void swap(Struct& a, Struct& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -182,7 +201,7 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; public: @@ -204,6 +223,7 @@ class LIBPROTOBUF_EXPORT Struct : public ::google::protobuf::Message /* @@protoc static const Message* internal_default_instance() { return reinterpret_cast<const Message*>(&_Struct_FieldsEntry_default_instance_); } ::google::protobuf::Metadata GetMetadata() const; }; + private: ::google::protobuf::internal::MapField< Struct_FieldsEntry, ::std::string, ::google::protobuf::Value, @@ -227,7 +247,21 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ CopyFrom(from); return *this; } + #if LANG_CXX11 + Value(Value&& from) noexcept + : Value() { + *this = ::std::move(from); + } + inline Value& operator=(Value&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -256,6 +290,9 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ void UnsafeArenaSwap(Value* other); void Swap(Value* other); + friend void swap(Value& a, Value& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -328,6 +365,9 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ static const int kStringValueFieldNumber = 3; const ::std::string& string_value() const; void set_string_value(const ::std::string& value); + #if LANG_CXX11 + void set_string_value(::std::string&& value); + #endif void set_string_value(const char* value); void set_string_value(const char* value, size_t size); ::std::string* mutable_string_value(); @@ -397,7 +437,7 @@ class LIBPROTOBUF_EXPORT Value : public ::google::protobuf::Message /* @@protoc_ inline void clear_has_kind(); ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; union KindUnion { @@ -427,7 +467,21 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro CopyFrom(from); return *this; } + #if LANG_CXX11 + ListValue(ListValue&& from) noexcept + : ListValue() { + *this = ::std::move(from); + } + inline ListValue& operator=(ListValue&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -446,6 +500,9 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro void UnsafeArenaSwap(ListValue* other); void Swap(ListValue* other); + friend void swap(ListValue& a, ListValue& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -508,7 +565,7 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::Value > values_; @@ -521,6 +578,10 @@ class LIBPROTOBUF_EXPORT ListValue : public ::google::protobuf::Message /* @@pro // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ // ------------------------------------------------------------------- // Struct @@ -636,6 +697,19 @@ inline void Value::set_string_value(const ::std::string& value) { GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Value.string_value) } +#if LANG_CXX11 +inline void Value::set_string_value(::std::string&& value) { + // @@protoc_insertion_point(field_set:google.protobuf.Value.string_value) + if (!has_string_value()) { + clear_kind(); + set_has_string_value(); + kind_.string_value_.UnsafeSetDefault(&::google::protobuf::internal::GetEmptyStringAlreadyInited()); + } + kind_.string_value_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Value.string_value) +} +#endif inline void Value::set_string_value(const char* value) { GOOGLE_DCHECK(value != NULL); if (!has_string_value()) { @@ -963,6 +1037,9 @@ ListValue::values() const { return values_; } +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // ------------------------------------------------------------------- @@ -977,7 +1054,6 @@ ListValue::values() const { } // namespace protobuf } // namespace google -#ifndef SWIG namespace google { namespace protobuf { @@ -989,7 +1065,6 @@ inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::NullValue>() } // namespace protobuf } // namespace google -#endif // SWIG // @@protoc_insertion_point(global_scope) diff --git a/src/google/protobuf/stubs/common.cc b/src/google/protobuf/stubs/common.cc index 14655916..78aa4d64 100644 --- a/src/google/protobuf/stubs/common.cc +++ b/src/google/protobuf/stubs/common.cc @@ -416,13 +416,26 @@ uint32 ghtonl(uint32 x) { namespace internal { typedef void OnShutdownFunc(); -vector<void (*)()>* shutdown_functions = NULL; -Mutex* shutdown_functions_mutex = NULL; +struct ShutdownData { + ~ShutdownData() { + for (int i = 0; i < functions.size(); i++) { + functions[i](); + } + for (int i = 0; i < strings.size(); i++) { + strings[i]->~string(); + } + } + + vector<void (*)()> functions; + vector<const std::string*> strings; + Mutex mutex; +}; + +ShutdownData* shutdown_data = NULL; GOOGLE_PROTOBUF_DECLARE_ONCE(shutdown_functions_init); void InitShutdownFunctions() { - shutdown_functions = new vector<void (*)()>; - shutdown_functions_mutex = new Mutex; + shutdown_data = new ShutdownData; } inline void InitShutdownFunctionsOnce() { @@ -431,8 +444,14 @@ inline void InitShutdownFunctionsOnce() { void OnShutdown(void (*func)()) { InitShutdownFunctionsOnce(); - MutexLock lock(shutdown_functions_mutex); - shutdown_functions->push_back(func); + MutexLock lock(&shutdown_data->mutex); + shutdown_data->functions.push_back(func); +} + +void OnShutdownDestroyString(const std::string* ptr) { + InitShutdownFunctionsOnce(); + MutexLock lock(&shutdown_data->mutex); + shutdown_data->strings.push_back(ptr); } } // namespace internal @@ -445,15 +464,10 @@ void ShutdownProtobufLibrary() { // called. // Make it safe to call this multiple times. - if (internal::shutdown_functions == NULL) return; + if (internal::shutdown_data == NULL) return; - for (int i = 0; i < internal::shutdown_functions->size(); i++) { - internal::shutdown_functions->at(i)(); - } - delete internal::shutdown_functions; - internal::shutdown_functions = NULL; - delete internal::shutdown_functions_mutex; - internal::shutdown_functions_mutex = NULL; + delete internal::shutdown_data; + internal::shutdown_data = NULL; } #if PROTOBUF_USE_EXCEPTIONS diff --git a/src/google/protobuf/stubs/common.h b/src/google/protobuf/stubs/common.h index 60874e09..79d615df 100644 --- a/src/google/protobuf/stubs/common.h +++ b/src/google/protobuf/stubs/common.h @@ -200,7 +200,8 @@ namespace internal { // Register a function to be called when ShutdownProtocolBuffers() is called. LIBPROTOBUF_EXPORT void OnShutdown(void (*func)()); - +// Destroy the string (call string destructor) +LIBPROTOBUF_EXPORT void OnShutdownDestroyString(const std::string* ptr); } // namespace internal #if PROTOBUF_USE_EXCEPTIONS diff --git a/src/google/protobuf/stubs/mutex.h b/src/google/protobuf/stubs/mutex.h index 7ef1cb69..174290f6 100644 --- a/src/google/protobuf/stubs/mutex.h +++ b/src/google/protobuf/stubs/mutex.h @@ -70,14 +70,6 @@ class LIBPROTOBUF_EXPORT Mutex { GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(Mutex); }; -// Undefine the macros to workaround the conflicts with Google internal -// MutexLock implementation. -// TODO(liujisi): Remove the undef once internal macros are removed. -#undef MutexLock -#undef ReaderMutexLock -#undef WriterMutexLock -#undef MutexLockMaybe - // MutexLock(mu) acquires mu when constructed and releases it when destroyed. class LIBPROTOBUF_EXPORT MutexLock { public: diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h index 6ec5e001..ca9a1501 100644 --- a/src/google/protobuf/stubs/port.h +++ b/src/google/protobuf/stubs/port.h @@ -461,6 +461,10 @@ class BigEndian { } }; +#ifndef GOOGLE_ATTRIBUTE_SECTION_VARIABLE +#define GOOGLE_ATTRIBUTE_SECTION_VARIABLE(name) +#endif + } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/testing/googletest.h b/src/google/protobuf/testing/googletest.h index c0d99e69..04b3019e 100644 --- a/src/google/protobuf/testing/googletest.h +++ b/src/google/protobuf/testing/googletest.h @@ -37,7 +37,7 @@ #include <map> #include <vector> #include <google/protobuf/stubs/common.h> - +#include <gmock/gmock.h> // Disable death tests if we use exceptions in CHECK(). #if !PROTOBUF_USE_EXCEPTIONS && defined(GTEST_HAS_DEATH_TEST) #define PROTOBUF_HAS_DEATH_TEST diff --git a/src/google/protobuf/text_format.cc b/src/google/protobuf/text_format.cc index 04c887e0..1ebbdf86 100644 --- a/src/google/protobuf/text_format.cc +++ b/src/google/protobuf/text_format.cc @@ -42,20 +42,21 @@ #include <google/protobuf/text_format.h> -#include <google/protobuf/descriptor.h> -#include <google/protobuf/dynamic_message.h> -#include <google/protobuf/repeated_field.h> -#include <google/protobuf/wire_format_lite.h> +#include <google/protobuf/stubs/stringprintf.h> +#include <google/protobuf/any.h> #include <google/protobuf/io/strtod.h> #include <google/protobuf/io/coded_stream.h> +#include <google/protobuf/io/tokenizer.h> #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/io/zero_copy_stream_impl.h> -#include <google/protobuf/unknown_field_set.h> #include <google/protobuf/descriptor.pb.h> -#include <google/protobuf/io/tokenizer.h> -#include <google/protobuf/any.h> -#include <google/protobuf/stubs/stringprintf.h> +#include <google/protobuf/descriptor.h> +#include <google/protobuf/dynamic_message.h> +#include <google/protobuf/repeated_field.h> +#include <google/protobuf/unknown_field_set.h> +#include <google/protobuf/wire_format_lite.h> #include <google/protobuf/stubs/strutil.h> + #include <google/protobuf/stubs/map_util.h> #include <google/protobuf/stubs/stl_util.h> @@ -364,7 +365,7 @@ class TextFormat::Parser::ParserImpl { const Descriptor* descriptor = message->GetDescriptor(); string field_name; - + bool reserved_field = false; const FieldDescriptor* field = NULL; int start_line = tokenizer_.current().line; int start_column = tokenizer_.current().column; @@ -426,6 +427,8 @@ class TextFormat::Parser::ParserImpl { if (allow_field_number_ && safe_strto32(field_name, &field_number)) { if (descriptor->IsExtensionNumber(field_number)) { field = reflection->FindKnownExtensionByNumber(field_number); + } else if (descriptor->IsReservedNumber(field_number)) { + reserved_field = true; } else { field = descriptor->FindFieldByNumber(field_number); } @@ -454,9 +457,13 @@ class TextFormat::Parser::ParserImpl { LowerString(&lower_field_name); field = descriptor->FindFieldByLowercaseName(lower_field_name); } + + if (field == NULL) { + reserved_field = descriptor->IsReservedName(field_name); + } } - if (field == NULL) { + if (field == NULL && !reserved_field) { if (!allow_unknown_field_) { ReportError("Message type \"" + descriptor->full_name() + "\" has no field named \"" + field_name + "\"."); @@ -468,9 +475,10 @@ class TextFormat::Parser::ParserImpl { } } - // Skips unknown field. + // Skips unknown or reserved fields. if (field == NULL) { - GOOGLE_CHECK(allow_unknown_field_); + GOOGLE_CHECK(allow_unknown_field_ || reserved_field); + // Try to guess the type of this field. // If this field is not a message, there should be a ":" between the // field name and the field value and also the field value should not @@ -1147,7 +1155,8 @@ label_skip_parsing: // =========================================================================== // Internal class for writing text to the io::ZeroCopyOutputStream. Adapted // from the Printer found in //google/protobuf/io/printer.h -class TextFormat::Printer::TextGenerator { +class TextFormat::Printer::TextGenerator + : public TextFormat::BaseTextGenerator { public: explicit TextGenerator(io::ZeroCopyOutputStream* output, int initial_indent_level) @@ -1156,9 +1165,8 @@ class TextFormat::Printer::TextGenerator { buffer_size_(0), at_start_of_line_(true), failed_(false), - indent_(""), + indent_level_(initial_indent_level), initial_indent_level_(initial_indent_level) { - indent_.resize(initial_indent_level_ * 2, ' '); } ~TextGenerator() { @@ -1173,50 +1181,45 @@ class TextFormat::Printer::TextGenerator { // inserted at the beginning of each line of text. Indent() may be called // multiple times to produce deeper indents. void Indent() { - indent_ += " "; + ++indent_level_; } // Reduces the current indent level by two spaces, or crashes if the indent // level is zero. void Outdent() { - if (indent_.empty() || - indent_.size() < initial_indent_level_ * 2) { + if (indent_level_ == 0 || + indent_level_ < initial_indent_level_) { GOOGLE_LOG(DFATAL) << " Outdent() without matching Indent()."; return; } - indent_.resize(indent_.size() - 2); - } - - // Print text to the output stream. - void Print(const string& str) { - Print(str.data(), str.size()); - } - - // Print text to the output stream. - void Print(const char* text) { - Print(text, strlen(text)); + --indent_level_; } // Print text to the output stream. void Print(const char* text, size_t size) { - size_t pos = 0; // The number of bytes we've written so far. - - for (size_t i = 0; i < size; i++) { - if (text[i] == '\n') { - // Saw newline. If there is more text, we may need to insert an indent - // here. So, write what we have so far, including the '\n'. - Write(text + pos, i - pos + 1); - pos = i + 1; - - // Setting this true will cause the next Write() to insert an indent - // first. + if (indent_level_ > 0) { + size_t pos = 0; // The number of bytes we've written so far. + for (size_t i = 0; i < size; i++) { + if (text[i] == '\n') { + // Saw newline. If there is more text, we may need to insert an + // indent here. So, write what we have so far, including the '\n'. + Write(text + pos, i - pos + 1); + pos = i + 1; + + // Setting this true will cause the next Write() to insert an indent + // first. + at_start_of_line_ = true; + } + } + // Write the rest. + Write(text + pos, size - pos); + } else { + Write(text, size); + if (text[size - 1] == '\n') { at_start_of_line_ = true; } } - - // Write the rest. - Write(text + pos, size - pos); } // True if any write to the underlying stream failed. (We don't just @@ -1234,7 +1237,7 @@ class TextFormat::Printer::TextGenerator { if (at_start_of_line_) { // Insert an indent. at_start_of_line_ = false; - Write(indent_.data(), indent_.size()); + WriteIndent(); if (failed_) return; } @@ -1256,13 +1259,35 @@ class TextFormat::Printer::TextGenerator { buffer_size_ -= size; } + void WriteIndent() { + if (indent_level_ == 0) { return; } + GOOGLE_DCHECK(!failed_); + int size = 2 * indent_level_; + + while (size > buffer_size_) { + // Data exceeds space in the buffer. Write what we can and request a new + // buffer. + memset(buffer_, ' ', buffer_size_); + size -= buffer_size_; + void* void_buffer; + failed_ = !output_->Next(&void_buffer, &buffer_size_); + if (failed_) return; + buffer_ = reinterpret_cast<char*>(void_buffer); + } + + // Buffer is big enough to receive the data; copy it. + memset(buffer_, ' ', size); + buffer_ += size; + buffer_size_ -= size; + } + io::ZeroCopyOutputStream* const output_; char* buffer_; int buffer_size_; bool at_start_of_line_; bool failed_; - string indent_; + int indent_level_; int initial_indent_level_; }; @@ -1380,90 +1405,272 @@ bool TextFormat::Parser::ParseFieldValueFromString( // =========================================================================== -// The default implementation for FieldValuePrinter. The base class just -// does simple formatting. That way, deriving classes could decide to fallback -// to that behavior. +TextFormat::BaseTextGenerator::~BaseTextGenerator() {} + +namespace { + +// A BaseTextGenerator that writes to a string. +class StringBaseTextGenerator : public TextFormat::BaseTextGenerator { + public: + void Print(const char* text, size_t size) { output_.append(text, size); } + +#if LANG_CXX11 + string Consume() && { return std::move(output_); } +#else // !LANG_CXX11 + const string& Get() { return output_; } +#endif // LANG_CXX11 + + private: + string output_; +}; + +} // namespace + +// The default implementation for FieldValuePrinter. We just delegate the +// implementation to the default FastFieldValuePrinter to avoid duplicating the +// logic. TextFormat::FieldValuePrinter::FieldValuePrinter() {} TextFormat::FieldValuePrinter::~FieldValuePrinter() {} + +#if LANG_CXX11 +#define FORWARD_IMPL(fn, ...) \ + StringBaseTextGenerator generator; \ + delegate_.fn(__VA_ARGS__, &generator); \ + return std::move(generator).Consume() +#else // !LANG_CXX11 +#define FORWARD_IMPL(fn, ...) \ + StringBaseTextGenerator generator; \ + delegate_.fn(__VA_ARGS__, &generator); \ + return generator.Get() +#endif // LANG_CXX11 + string TextFormat::FieldValuePrinter::PrintBool(bool val) const { - return val ? "true" : "false"; + FORWARD_IMPL(PrintBool, val); } string TextFormat::FieldValuePrinter::PrintInt32(int32 val) const { - return SimpleItoa(val); + FORWARD_IMPL(PrintInt32, val); } string TextFormat::FieldValuePrinter::PrintUInt32(uint32 val) const { - return SimpleItoa(val); + FORWARD_IMPL(PrintUInt32, val); } string TextFormat::FieldValuePrinter::PrintInt64(int64 val) const { - return SimpleItoa(val); + FORWARD_IMPL(PrintInt64, val); } string TextFormat::FieldValuePrinter::PrintUInt64(uint64 val) const { - return SimpleItoa(val); + FORWARD_IMPL(PrintUInt64, val); } string TextFormat::FieldValuePrinter::PrintFloat(float val) const { - return SimpleFtoa(val); + FORWARD_IMPL(PrintFloat, val); } string TextFormat::FieldValuePrinter::PrintDouble(double val) const { - return SimpleDtoa(val); + FORWARD_IMPL(PrintDouble, val); } string TextFormat::FieldValuePrinter::PrintString(const string& val) const { - string printed("\""); - CEscapeAndAppend(val, &printed); - printed.push_back('\"'); - return printed; + FORWARD_IMPL(PrintString, val); } string TextFormat::FieldValuePrinter::PrintBytes(const string& val) const { return PrintString(val); } string TextFormat::FieldValuePrinter::PrintEnum(int32 val, const string& name) const { - return name; + FORWARD_IMPL(PrintEnum, val, name); } string TextFormat::FieldValuePrinter::PrintFieldName( const Message& message, const Reflection* reflection, const FieldDescriptor* field) const { - if (field->is_extension()) { - // We special-case MessageSet elements for compatibility with proto1. - if (field->containing_type()->options().message_set_wire_format() - && field->type() == FieldDescriptor::TYPE_MESSAGE - && field->is_optional() - && field->extension_scope() == field->message_type()) { - return StrCat("[", field->message_type()->full_name(), "]"); - } else { - return StrCat("[", field->full_name(), "]"); - } - } else if (field->type() == FieldDescriptor::TYPE_GROUP) { - // Groups must be serialized with their original capitalization. - return field->message_type()->name(); - } else { - return field->name(); - } + FORWARD_IMPL(PrintFieldName, message, reflection, field); } string TextFormat::FieldValuePrinter::PrintMessageStart( const Message& message, int field_index, int field_count, bool single_line_mode) const { - return single_line_mode ? " { " : " {\n"; + FORWARD_IMPL(PrintMessageStart, message, field_index, field_count, + single_line_mode); } string TextFormat::FieldValuePrinter::PrintMessageEnd( const Message& message, int field_index, int field_count, bool single_line_mode) const { - return single_line_mode ? "} " : "}\n"; + FORWARD_IMPL(PrintMessageEnd, message, field_index, field_count, + single_line_mode); +} +#undef FORWARD_IMPL + +TextFormat::FastFieldValuePrinter::FastFieldValuePrinter() {} +TextFormat::FastFieldValuePrinter::~FastFieldValuePrinter() {} +void TextFormat::FastFieldValuePrinter::PrintBool( + bool val, BaseTextGenerator* generator) const { + if (val) { + generator->PrintLiteral("true"); + } else { + generator->PrintLiteral("false"); + } +} +void TextFormat::FastFieldValuePrinter::PrintInt32( + int32 val, BaseTextGenerator* generator) const { + generator->PrintString(SimpleItoa(val)); +} +void TextFormat::FastFieldValuePrinter::PrintUInt32( + uint32 val, BaseTextGenerator* generator) const { + generator->PrintString(SimpleItoa(val)); +} +void TextFormat::FastFieldValuePrinter::PrintInt64( + int64 val, BaseTextGenerator* generator) const { + generator->PrintString(SimpleItoa(val)); +} +void TextFormat::FastFieldValuePrinter::PrintUInt64( + uint64 val, BaseTextGenerator* generator) const { + generator->PrintString(SimpleItoa(val)); +} +void TextFormat::FastFieldValuePrinter::PrintFloat( + float val, BaseTextGenerator* generator) const { + generator->PrintString(SimpleFtoa(val)); +} +void TextFormat::FastFieldValuePrinter::PrintDouble( + double val, BaseTextGenerator* generator) const { + generator->PrintString(SimpleDtoa(val)); +} +void TextFormat::FastFieldValuePrinter::PrintEnum( + int32 val, const string& name, BaseTextGenerator* generator) const { + generator->PrintString(name); +} + +void TextFormat::FastFieldValuePrinter::PrintString( + const string& val, BaseTextGenerator* generator) const { + generator->PrintLiteral("\""); + generator->PrintString(CEscape(val)); + generator->PrintLiteral("\""); +} +void TextFormat::FastFieldValuePrinter::PrintBytes( + const string& val, BaseTextGenerator* generator) const { + PrintString(val, generator); +} +void TextFormat::FastFieldValuePrinter::PrintFieldName( + const Message& message, const Reflection* reflection, + const FieldDescriptor* field, BaseTextGenerator* generator) const { + if (field->is_extension()) { + generator->PrintLiteral("["); + // We special-case MessageSet elements for compatibility with proto1. + if (field->containing_type()->options().message_set_wire_format() && + field->type() == FieldDescriptor::TYPE_MESSAGE && + field->is_optional() && + field->extension_scope() == field->message_type()) { + generator->PrintString(field->message_type()->full_name()); + } else { + generator->PrintString(field->full_name()); + } + generator->PrintLiteral("]"); + } else if (field->type() == FieldDescriptor::TYPE_GROUP) { + // Groups must be serialized with their original capitalization. + generator->PrintString(field->message_type()->name()); + } else { + generator->PrintString(field->name()); + } +} +void TextFormat::FastFieldValuePrinter::PrintMessageStart( + const Message& message, int field_index, int field_count, + bool single_line_mode, BaseTextGenerator* generator) const { + if (single_line_mode) { + generator->PrintLiteral(" { "); + } else { + generator->PrintLiteral(" {\n"); + } +} +void TextFormat::FastFieldValuePrinter::PrintMessageEnd( + const Message& message, int field_index, int field_count, + bool single_line_mode, BaseTextGenerator* generator) const { + if (single_line_mode) { + generator->PrintLiteral("} "); + } else { + generator->PrintLiteral("}\n"); + } } namespace { + +// A legacy compatibility wrapper. Takes ownership of the delegate. +class FieldValuePrinterWrapper : public TextFormat::FastFieldValuePrinter { + public: + explicit FieldValuePrinterWrapper( + const TextFormat::FieldValuePrinter* delegate) + : delegate_(delegate) {} + + void SetDelegate(const TextFormat::FieldValuePrinter* delegate) { + delegate_.reset(delegate); + } + + void PrintBool(bool val, TextFormat::BaseTextGenerator* generator) const { + generator->PrintString(delegate_->PrintBool(val)); + } + void PrintInt32(int32 val, TextFormat::BaseTextGenerator* generator) const { + generator->PrintString(delegate_->PrintInt32(val)); + } + void PrintUInt32(uint32 val, TextFormat::BaseTextGenerator* generator) const { + generator->PrintString(delegate_->PrintUInt32(val)); + } + void PrintInt64(int64 val, TextFormat::BaseTextGenerator* generator) const { + generator->PrintString(delegate_->PrintInt64(val)); + } + void PrintUInt64(uint64 val, TextFormat::BaseTextGenerator* generator) const { + generator->PrintString(delegate_->PrintUInt64(val)); + } + void PrintFloat(float val, TextFormat::BaseTextGenerator* generator) const { + generator->PrintString(delegate_->PrintFloat(val)); + } + void PrintDouble(double val, TextFormat::BaseTextGenerator* generator) const { + generator->PrintString(delegate_->PrintDouble(val)); + } + void PrintString(const string& val, + TextFormat::BaseTextGenerator* generator) const { + generator->PrintString(delegate_->PrintString(val)); + } + void PrintBytes(const string& val, + TextFormat::BaseTextGenerator* generator) const { + generator->PrintString(delegate_->PrintBytes(val)); + } + void PrintEnum(int32 val, const string& name, + TextFormat::BaseTextGenerator* generator) const { + generator->PrintString(delegate_->PrintEnum(val, name)); + } + void PrintFieldName(const Message& message, const Reflection* reflection, + const FieldDescriptor* field, + TextFormat::BaseTextGenerator* generator) const { + generator->PrintString( + delegate_->PrintFieldName(message, reflection, field)); + } + void PrintMessageStart(const Message& message, int field_index, + int field_count, bool single_line_mode, + TextFormat::BaseTextGenerator* generator) const { + generator->PrintString(delegate_->PrintMessageStart( + message, field_index, field_count, single_line_mode)); + } + void PrintMessageEnd(const Message& message, int field_index, int field_count, + bool single_line_mode, + TextFormat::BaseTextGenerator* generator) const { + generator->PrintString(delegate_->PrintMessageEnd( + message, field_index, field_count, single_line_mode)); + } + + private: + google::protobuf::scoped_ptr<const TextFormat::FieldValuePrinter> delegate_; +}; + // Our own specialization: for UTF8 escaped strings. -class FieldValuePrinterUtf8Escaping : public TextFormat::FieldValuePrinter { +class FastFieldValuePrinterUtf8Escaping + : public TextFormat::FastFieldValuePrinter { public: - virtual string PrintString(const string& val) const { - return StrCat("\"", strings::Utf8SafeCEscape(val), "\""); + void PrintString(const string& val, + TextFormat::BaseTextGenerator* generator) const { + generator->PrintLiteral("\""); + generator->PrintString(strings::Utf8SafeCEscape(val)); + generator->PrintLiteral("\""); } - virtual string PrintBytes(const string& val) const { - return TextFormat::FieldValuePrinter::PrintString(val); + void PrintBytes(const string& val, + TextFormat::BaseTextGenerator* generator) const { + return FastFieldValuePrinter::PrintString(val, generator); } }; @@ -1486,19 +1693,39 @@ TextFormat::Printer::~Printer() { } void TextFormat::Printer::SetUseUtf8StringEscaping(bool as_utf8) { - SetDefaultFieldValuePrinter(as_utf8 - ? new FieldValuePrinterUtf8Escaping() - : new FieldValuePrinter()); + SetDefaultFieldValuePrinter(as_utf8 ? new FastFieldValuePrinterUtf8Escaping() + : new FastFieldValuePrinter()); } void TextFormat::Printer::SetDefaultFieldValuePrinter( const FieldValuePrinter* printer) { + default_field_value_printer_.reset(new FieldValuePrinterWrapper(printer)); +} + +void TextFormat::Printer::SetDefaultFieldValuePrinter( + const FastFieldValuePrinter* printer) { default_field_value_printer_.reset(printer); } bool TextFormat::Printer::RegisterFieldValuePrinter( const FieldDescriptor* field, const FieldValuePrinter* printer) { + if (field == NULL || printer == NULL) { + return false; + } + FieldValuePrinterWrapper* const wrapper = + new FieldValuePrinterWrapper(NULL); + if (custom_printers_.insert(std::make_pair(field, wrapper)).second) { + wrapper->SetDelegate(printer); + return true; + } else { + delete wrapper; + return false; + } +} + +bool TextFormat::Printer::RegisterFieldValuePrinter( + const FieldDescriptor* field, const FastFieldValuePrinter* printer) { return field != NULL && printer != NULL && custom_printers_.insert(std::make_pair(field, printer)).second; } @@ -1527,7 +1754,7 @@ bool TextFormat::Printer::Print(const Message& message, io::ZeroCopyOutputStream* output) const { TextGenerator generator(output, initial_indent_level_); - Print(message, generator); + Print(message, &generator); // Output false if the generator failed internally. return !generator.failed(); @@ -1538,7 +1765,7 @@ bool TextFormat::Printer::PrintUnknownFields( io::ZeroCopyOutputStream* output) const { TextGenerator generator(output, initial_indent_level_); - PrintUnknownFields(unknown_fields, generator); + PrintUnknownFields(unknown_fields, &generator); // Output false if the generator failed internally. return !generator.failed(); @@ -1556,7 +1783,7 @@ struct FieldIndexSorter { } // namespace bool TextFormat::Printer::PrintAny(const Message& message, - TextGenerator& generator) const { + TextGenerator* generator) const { const FieldDescriptor* type_url_field; const FieldDescriptor* value_field; if (!internal::GetAnyFieldDescriptors(message, &type_url_field, @@ -1589,20 +1816,21 @@ bool TextFormat::Printer::PrintAny(const Message& message, GOOGLE_LOG(WARNING) << type_url << ": failed to parse contents"; return false; } - generator.Print(StrCat("[", type_url, "]")); - const FieldValuePrinter* printer = FindWithDefault( + generator->PrintLiteral("["); + generator->PrintString(type_url); + generator->PrintLiteral("]"); + const FastFieldValuePrinter* printer = FindWithDefault( custom_printers_, value_field, default_field_value_printer_.get()); - generator.Print( - printer->PrintMessageStart(message, -1, 0, single_line_mode_)); - generator.Indent(); + printer->PrintMessageStart(message, -1, 0, single_line_mode_, generator); + generator->Indent(); Print(*value_message, generator); - generator.Outdent(); - generator.Print(printer->PrintMessageEnd(message, -1, 0, single_line_mode_)); + generator->Outdent(); + printer->PrintMessageEnd(message, -1, 0, single_line_mode_, generator); return true; } void TextFormat::Printer::Print(const Message& message, - TextGenerator& generator) const { + TextGenerator* generator) const { const Descriptor* descriptor = message.GetDescriptor(); const Reflection* reflection = message.GetReflection(); if (descriptor->full_name() == internal::kAnyFullTypeName && expand_any_ && @@ -1634,13 +1862,13 @@ void TextFormat::Printer::PrintFieldValueToString( io::StringOutputStream output_stream(output); TextGenerator generator(&output_stream, initial_indent_level_); - PrintFieldValue(message, message.GetReflection(), field, index, generator); + PrintFieldValue(message, message.GetReflection(), field, index, &generator); } void TextFormat::Printer::PrintField(const Message& message, const Reflection* reflection, const FieldDescriptor* field, - TextGenerator& generator) const { + TextGenerator* generator) const { if (use_short_repeated_primitives_ && field->is_repeated() && field->cpp_type() != FieldDescriptor::CPPTYPE_STRING && @@ -1669,92 +1897,88 @@ void TextFormat::Printer::PrintField(const Message& message, PrintFieldName(message, reflection, field, generator); if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { - const FieldValuePrinter* printer = FindWithDefault( + const FastFieldValuePrinter* printer = FindWithDefault( custom_printers_, field, default_field_value_printer_.get()); const Message& sub_message = field->is_repeated() ? (is_map ? *map_entries[j] : reflection->GetRepeatedMessage(message, field, j)) : reflection->GetMessage(message, field); - generator.Print( - printer->PrintMessageStart( - sub_message, field_index, count, single_line_mode_)); - generator.Indent(); + printer->PrintMessageStart(sub_message, field_index, count, + single_line_mode_, generator); + generator->Indent(); Print(sub_message, generator); - generator.Outdent(); - generator.Print( - printer->PrintMessageEnd( - sub_message, field_index, count, single_line_mode_)); + generator->Outdent(); + printer->PrintMessageEnd(sub_message, field_index, count, + single_line_mode_, generator); } else { - generator.Print(": "); + generator->PrintLiteral(": "); // Write the field value. PrintFieldValue(message, reflection, field, field_index, generator); if (single_line_mode_) { - generator.Print(" "); + generator->PrintLiteral(" "); } else { - generator.Print("\n"); + generator->PrintLiteral("\n"); } } } } void TextFormat::Printer::PrintShortRepeatedField( - const Message& message, - const Reflection* reflection, - const FieldDescriptor* field, - TextGenerator& generator) const { + const Message& message, const Reflection* reflection, + const FieldDescriptor* field, TextGenerator* generator) const { // Print primitive repeated field in short form. PrintFieldName(message, reflection, field, generator); int size = reflection->FieldSize(message, field); - generator.Print(": ["); + generator->PrintLiteral(": ["); for (int i = 0; i < size; i++) { - if (i > 0) generator.Print(", "); + if (i > 0) generator->PrintLiteral(", "); PrintFieldValue(message, reflection, field, i, generator); } if (single_line_mode_) { - generator.Print("] "); + generator->PrintLiteral("] "); } else { - generator.Print("]\n"); + generator->PrintLiteral("]\n"); } } void TextFormat::Printer::PrintFieldName(const Message& message, const Reflection* reflection, const FieldDescriptor* field, - TextGenerator& generator) const { + TextGenerator* generator) const { // if use_field_number_ is true, prints field number instead // of field name. if (use_field_number_) { - generator.Print(SimpleItoa(field->number())); + generator->PrintString(SimpleItoa(field->number())); return; } - const FieldValuePrinter* printer = FindWithDefault( + const FastFieldValuePrinter* printer = FindWithDefault( custom_printers_, field, default_field_value_printer_.get()); - generator.Print(printer->PrintFieldName(message, reflection, field)); + printer->PrintFieldName(message, reflection, field, generator); } -void TextFormat::Printer::PrintFieldValue( - const Message& message, - const Reflection* reflection, - const FieldDescriptor* field, - int index, - TextGenerator& generator) const { +void TextFormat::Printer::PrintFieldValue(const Message& message, + const Reflection* reflection, + const FieldDescriptor* field, + int index, + TextGenerator* generator) const { GOOGLE_DCHECK(field->is_repeated() || (index == -1)) << "Index must be -1 for non-repeated fields"; - const FieldValuePrinter* printer - = FindWithDefault(custom_printers_, field, - default_field_value_printer_.get()); + const FastFieldValuePrinter* printer = FindWithDefault( + custom_printers_, field, default_field_value_printer_.get()); switch (field->cpp_type()) { -#define OUTPUT_FIELD(CPPTYPE, METHOD) \ - case FieldDescriptor::CPPTYPE_##CPPTYPE: \ - generator.Print(printer->Print##METHOD(field->is_repeated() \ - ? reflection->GetRepeated##METHOD(message, field, index) \ - : reflection->Get##METHOD(message, field))); \ - break +#define OUTPUT_FIELD(CPPTYPE, METHOD) \ + case FieldDescriptor::CPPTYPE_##CPPTYPE: \ + printer->Print##METHOD( \ + field->is_repeated() \ + ? reflection->GetRepeated##METHOD(message, field, index) \ + : reflection->Get##METHOD(message, field), \ + generator); \ + break OUTPUT_FIELD( INT32, Int32); OUTPUT_FIELD( INT64, Int64); @@ -1780,10 +2004,10 @@ void TextFormat::Printer::PrintFieldValue( value_to_print = &truncated_value; } if (field->type() == FieldDescriptor::TYPE_STRING) { - generator.Print(printer->PrintString(*value_to_print)); + printer->PrintString(*value_to_print, generator); } else { GOOGLE_DCHECK_EQ(field->type(), FieldDescriptor::TYPE_BYTES); - generator.Print(printer->PrintBytes(*value_to_print)); + printer->PrintBytes(*value_to_print, generator); } break; } @@ -1795,7 +2019,7 @@ void TextFormat::Printer::PrintFieldValue( const EnumValueDescriptor* enum_desc = field->enum_type()->FindValueByNumber(enum_value); if (enum_desc != NULL) { - generator.Print(printer->PrintEnum(enum_value, enum_desc->name())); + printer->PrintEnum(enum_value, enum_desc->name(), generator); } else { // Ordinarily, enum_desc should not be null, because proto2 has the // invariant that set enum field values must be in-range, but with the @@ -1803,8 +2027,8 @@ void TextFormat::Printer::PrintFieldValue( // it is possible for the user to force an unknown integer value. So we // simply use the integer value itself as the enum value name in this // case. - generator.Print(printer->PrintEnum(enum_value, - StringPrintf("%d", enum_value))); + printer->PrintEnum(enum_value, StringPrintf("%d", enum_value), + generator); } break; } @@ -1867,90 +2091,93 @@ static string PaddedHex(IntType value) { } void TextFormat::Printer::PrintUnknownFields( - const UnknownFieldSet& unknown_fields, TextGenerator& generator) const { + const UnknownFieldSet& unknown_fields, TextGenerator* generator) const { for (int i = 0; i < unknown_fields.field_count(); i++) { const UnknownField& field = unknown_fields.field(i); string field_number = SimpleItoa(field.number()); switch (field.type()) { case UnknownField::TYPE_VARINT: - generator.Print(field_number); - generator.Print(": "); - generator.Print(SimpleItoa(field.varint())); + generator->PrintString(field_number); + generator->PrintLiteral(": "); + generator->PrintString(SimpleItoa(field.varint())); if (single_line_mode_) { - generator.Print(" "); + generator->PrintLiteral(" "); } else { - generator.Print("\n"); + generator->PrintLiteral("\n"); } break; case UnknownField::TYPE_FIXED32: { - generator.Print(field_number); - generator.Print(": 0x"); - generator.Print( + generator->PrintString(field_number); + generator->PrintLiteral(": 0x"); + generator->PrintString( StrCat(strings::Hex(field.fixed32(), strings::ZERO_PAD_8))); if (single_line_mode_) { - generator.Print(" "); + generator->PrintLiteral(" "); } else { - generator.Print("\n"); + generator->PrintLiteral("\n"); } break; } case UnknownField::TYPE_FIXED64: { - generator.Print(field_number); - generator.Print(": 0x"); - generator.Print( + generator->PrintString(field_number); + generator->PrintLiteral(": 0x"); + generator->PrintString( StrCat(strings::Hex(field.fixed64(), strings::ZERO_PAD_16))); if (single_line_mode_) { - generator.Print(" "); + generator->PrintLiteral(" "); } else { - generator.Print("\n"); + generator->PrintLiteral("\n"); } break; } case UnknownField::TYPE_LENGTH_DELIMITED: { - generator.Print(field_number); + generator->PrintString(field_number); const string& value = field.length_delimited(); UnknownFieldSet embedded_unknown_fields; if (!value.empty() && embedded_unknown_fields.ParseFromString(value)) { // This field is parseable as a Message. // So it is probably an embedded message. if (single_line_mode_) { - generator.Print(" { "); + generator->PrintLiteral(" { "); } else { - generator.Print(" {\n"); - generator.Indent(); + generator->PrintLiteral(" {\n"); + generator->Indent(); } PrintUnknownFields(embedded_unknown_fields, generator); if (single_line_mode_) { - generator.Print("} "); + generator->PrintLiteral("} "); } else { - generator.Outdent(); - generator.Print("}\n"); + generator->Outdent(); + generator->PrintLiteral("}\n"); } } else { // This field is not parseable as a Message. // So it is probably just a plain string. - string printed(": \""); - CEscapeAndAppend(value, &printed); - printed.append(single_line_mode_ ? "\" " : "\"\n"); - generator.Print(printed); + generator->PrintLiteral(": \""); + generator->PrintString(CEscape(value)); + if (single_line_mode_) { + generator->PrintLiteral("\" "); + } else { + generator->PrintLiteral("\"\n"); + } } break; } case UnknownField::TYPE_GROUP: - generator.Print(field_number); + generator->PrintString(field_number); if (single_line_mode_) { - generator.Print(" { "); + generator->PrintLiteral(" { "); } else { - generator.Print(" {\n"); - generator.Indent(); + generator->PrintLiteral(" {\n"); + generator->Indent(); } PrintUnknownFields(field.group(), generator); if (single_line_mode_) { - generator.Print("} "); + generator->PrintLiteral("} "); } else { - generator.Outdent(); - generator.Print("}\n"); + generator->Outdent(); + generator->PrintLiteral("}\n"); } break; } diff --git a/src/google/protobuf/text_format.h b/src/google/protobuf/text_format.h index 560fd391..cd0e307e 100644 --- a/src/google/protobuf/text_format.h +++ b/src/google/protobuf/text_format.h @@ -65,21 +65,22 @@ namespace io { class LIBPROTOBUF_EXPORT TextFormat { public: // Outputs a textual representation of the given message to the given - // output stream. + // output stream. Returns false if printing fails. static bool Print(const Message& message, io::ZeroCopyOutputStream* output); // Print the fields in an UnknownFieldSet. They are printed by tag number // only. Embedded messages are heuristically identified by attempting to - // parse them. + // parse them. Returns false if printing fails. static bool PrintUnknownFields(const UnknownFieldSet& unknown_fields, io::ZeroCopyOutputStream* output); // Like Print(), but outputs directly to a string. // Note: output will be cleared prior to printing, and will be left empty - // even if printing fails. + // even if printing fails. Returns false if printing fails. static bool PrintToString(const Message& message, string* output); - // Like PrintUnknownFields(), but outputs directly to a string. + // Like PrintUnknownFields(), but outputs directly to a string. Returns false + // if printing fails. static bool PrintUnknownFieldsToString(const UnknownFieldSet& unknown_fields, string* output); @@ -92,11 +93,57 @@ class LIBPROTOBUF_EXPORT TextFormat { int index, string* output); - // The default printer that converts scalar values from fields into - // their string representation. - // You can derive from this FieldValuePrinter if you want to have - // fields to be printed in a different way and register it at the - // Printer. + class LIBPROTOBUF_EXPORT BaseTextGenerator { + public: + virtual ~BaseTextGenerator(); + // Print text to the output stream. + virtual void Print(const char* text, size_t size) = 0; + + void PrintString(const string& str) { Print(str.data(), str.size()); } + + template <size_t n> + void PrintLiteral(const char (&text)[n]) { + Print(text, n - 1); // n includes the terminating zero character. + } + }; + + // The default printer that converts scalar values from fields into their + // string representation. + // You can derive from this FastFieldValuePrinter if you want to have fields + // to be printed in a different way and register it at the Printer. + class LIBPROTOBUF_EXPORT FastFieldValuePrinter { + public: + FastFieldValuePrinter(); + virtual ~FastFieldValuePrinter(); + virtual void PrintBool(bool val, BaseTextGenerator* generator) const; + virtual void PrintInt32(int32 val, BaseTextGenerator* generator) const; + virtual void PrintUInt32(uint32 val, BaseTextGenerator* generator) const; + virtual void PrintInt64(int64 val, BaseTextGenerator* generator) const; + virtual void PrintUInt64(uint64 val, BaseTextGenerator* generator) const; + virtual void PrintFloat(float val, BaseTextGenerator* generator) const; + virtual void PrintDouble(double val, BaseTextGenerator* generator) const; + virtual void PrintString(const string& val, + BaseTextGenerator* generator) const; + virtual void PrintBytes(const string& val, + BaseTextGenerator* generator) const; + virtual void PrintEnum(int32 val, const string& name, + BaseTextGenerator* generator) const; + virtual void PrintFieldName(const Message& message, + const Reflection* reflection, + const FieldDescriptor* field, + BaseTextGenerator* generator) const; + virtual void PrintMessageStart(const Message& message, int field_index, + int field_count, bool single_line_mode, + BaseTextGenerator* generator) const; + virtual void PrintMessageEnd(const Message& message, int field_index, + int field_count, bool single_line_mode, + BaseTextGenerator* generator) const; + + private: + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FastFieldValuePrinter); + }; + +// DEPRECATED: Please use FastFieldValuePrinter. class LIBPROTOBUF_EXPORT FieldValuePrinter { public: FieldValuePrinter(); @@ -124,6 +171,7 @@ class LIBPROTOBUF_EXPORT TextFormat { bool single_line_mode) const; private: + FastFieldValuePrinter delegate_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldValuePrinter); }; @@ -183,12 +231,13 @@ class LIBPROTOBUF_EXPORT TextFormat { // Set true to output UTF-8 instead of ASCII. The only difference // is that bytes >= 0x80 in string fields will not be escaped, // because they are assumed to be part of UTF-8 multi-byte - // sequences. This will change the default FieldValuePrinter. + // sequences. This will change the default FastFieldValuePrinter. void SetUseUtf8StringEscaping(bool as_utf8); - // Set the default FieldValuePrinter that is used for all fields that + // Set the default (Fast)FieldValuePrinter that is used for all fields that // don't have a field-specific printer registered. // Takes ownership of the printer. + void SetDefaultFieldValuePrinter(const FastFieldValuePrinter* printer); void SetDefaultFieldValuePrinter(const FieldValuePrinter* printer); // Sets whether we want to hide unknown fields or not. @@ -233,13 +282,15 @@ class LIBPROTOBUF_EXPORT TextFormat { truncate_string_field_longer_than_ = truncate_string_field_longer_than; } - // Register a custom field-specific FieldValuePrinter for fields + // Register a custom field-specific (Fast)FieldValuePrinter for fields // with a particular FieldDescriptor. // Returns "true" if the registration succeeded, or "false", if there is // already a printer for that FieldDescriptor. // Takes ownership of the printer on successful registration. bool RegisterFieldValuePrinter(const FieldDescriptor* field, const FieldValuePrinter* printer); + bool RegisterFieldValuePrinter(const FieldDescriptor* field, + const FastFieldValuePrinter* printer); private: // Forward declaration of an internal class used to print the text @@ -248,43 +299,38 @@ class LIBPROTOBUF_EXPORT TextFormat { // Internal Print method, used for writing to the OutputStream via // the TextGenerator class. - void Print(const Message& message, - TextGenerator& generator) const; + void Print(const Message& message, TextGenerator* generator) const; // Print a single field. - void PrintField(const Message& message, - const Reflection* reflection, + void PrintField(const Message& message, const Reflection* reflection, const FieldDescriptor* field, - TextGenerator& generator) const; + TextGenerator* generator) const; // Print a repeated primitive field in short form. void PrintShortRepeatedField(const Message& message, const Reflection* reflection, const FieldDescriptor* field, - TextGenerator& generator) const; + TextGenerator* generator) const; // Print the name of a field -- i.e. everything that comes before the // ':' for a single name/value pair. - void PrintFieldName(const Message& message, - const Reflection* reflection, + void PrintFieldName(const Message& message, const Reflection* reflection, const FieldDescriptor* field, - TextGenerator& generator) const; + TextGenerator* generator) const; // Outputs a textual representation of the value of the field supplied on // the message supplied or the default value if not set. - void PrintFieldValue(const Message& message, - const Reflection* reflection, - const FieldDescriptor* field, - int index, - TextGenerator& generator) const; + void PrintFieldValue(const Message& message, const Reflection* reflection, + const FieldDescriptor* field, int index, + TextGenerator* generator) const; // Print the fields in an UnknownFieldSet. They are printed by tag number // only. Embedded messages are heuristically identified by attempting to // parse them. void PrintUnknownFields(const UnknownFieldSet& unknown_fields, - TextGenerator& generator) const; + TextGenerator* generator) const; - bool PrintAny(const Message& message, TextGenerator& generator) const; + bool PrintAny(const Message& message, TextGenerator* generator) const; int initial_indent_level_; @@ -302,9 +348,9 @@ class LIBPROTOBUF_EXPORT TextFormat { int64 truncate_string_field_longer_than_; - google::protobuf::scoped_ptr<const FieldValuePrinter> default_field_value_printer_; - typedef std::map<const FieldDescriptor*, - const FieldValuePrinter*> CustomPrinterMap; + google::protobuf::scoped_ptr<const FastFieldValuePrinter> default_field_value_printer_; + typedef std::map<const FieldDescriptor*, const FastFieldValuePrinter*> + CustomPrinterMap; CustomPrinterMap custom_printers_; }; diff --git a/src/google/protobuf/text_format_unittest.cc b/src/google/protobuf/text_format_unittest.cc index 422a86b4..f823bcb2 100644 --- a/src/google/protobuf/text_format_unittest.cc +++ b/src/google/protobuf/text_format_unittest.cc @@ -53,6 +53,7 @@ #include <google/protobuf/unittest_mset_wire_format.pb.h> #include <google/protobuf/io/tokenizer.h> #include <google/protobuf/io/zero_copy_stream_impl.h> + #include <google/protobuf/stubs/strutil.h> #include <google/protobuf/stubs/substitute.h> #include <google/protobuf/testing/googletest.h> @@ -454,13 +455,29 @@ TEST_F(TextFormatTest, FieldSpecificCustomPrinter) { EXPECT_EQ("optional_int32: value-is(42)\nrepeated_int32: 42\n", text); } +TEST_F(TextFormatTest, FieldSpecificCustomPrinterRegisterSameFieldTwice) { + protobuf_unittest::TestAllTypes message; + TextFormat::Printer printer; + const FieldDescriptor* const field = + message.GetDescriptor()->FindFieldByName("optional_int32"); + ASSERT_TRUE(printer.RegisterFieldValuePrinter( + field, new CustomInt32FieldValuePrinter())); + const TextFormat::FieldValuePrinter* const rejected = + new CustomInt32FieldValuePrinter(); + ASSERT_FALSE(printer.RegisterFieldValuePrinter(field, rejected)); + delete rejected; +} + TEST_F(TextFormatTest, ErrorCasesRegisteringFieldValuePrinterShouldFail) { protobuf_unittest::TestAllTypes message; TextFormat::Printer printer; // NULL printer. EXPECT_FALSE(printer.RegisterFieldValuePrinter( message.GetDescriptor()->FindFieldByName("optional_int32"), - NULL)); + static_cast<const TextFormat::FieldValuePrinter*>(NULL))); + EXPECT_FALSE(printer.RegisterFieldValuePrinter( + message.GetDescriptor()->FindFieldByName("optional_int32"), + static_cast<const TextFormat::FastFieldValuePrinter*>(NULL))); // Because registration fails, the ownership of this printer is never taken. TextFormat::FieldValuePrinter my_field_printer; // NULL field diff --git a/src/google/protobuf/timestamp.pb.cc b/src/google/protobuf/timestamp.pb.cc index b2fe28a4..54f022a0 100644 --- a/src/google/protobuf/timestamp.pb.cc +++ b/src/google/protobuf/timestamp.pb.cc @@ -32,20 +32,20 @@ namespace { } // namespace PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField - const TableStruct::entries[] = { + const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField - const TableStruct::aux[] = { + const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ::google::protobuf::internal::AuxillaryParseTableField(), }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const - TableStruct::schema[] = { + TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { NULL, NULL, 0, -1, -1, false }, }; -const ::google::protobuf::uint32 TableStruct::offsets[] = { +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, _internal_metadata_), ~0u, // no _extensions_ @@ -54,8 +54,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, seconds_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Timestamp, nanos_), }; - -static const ::google::protobuf::internal::MigrationSchema schemas[] = { +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { 0, -1, sizeof(Timestamp)}, }; @@ -85,12 +84,6 @@ void protobuf_RegisterTypes(const ::std::string&) { } } // namespace - -void TableStruct::Shutdown() { - _Timestamp_default_instance_.Shutdown(); - delete file_level_metadata[0].reflection; -} - void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -104,7 +97,7 @@ void InitDefaults() { } void AddDescriptorsImpl() { InitDefaults(); - static const char descriptor[] = { + static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { "\n\037google/protobuf/timestamp.proto\022\017googl" "e.protobuf\"+\n\tTimestamp\022\017\n\007seconds\030\001 \001(\003" "\022\r\n\005nanos\030\002 \001(\005B~\n\023com.google.protobufB\016" @@ -116,14 +109,13 @@ void AddDescriptorsImpl() { descriptor, 231); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/timestamp.proto", &protobuf_RegisterTypes); - ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); } void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -151,9 +143,7 @@ Timestamp::Timestamp() Timestamp::Timestamp(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2ftimestamp_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Timestamp) @@ -182,6 +172,7 @@ Timestamp::~Timestamp() { void Timestamp::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -215,8 +206,13 @@ Timestamp* Timestamp::New(::google::protobuf::Arena* arena) const { void Timestamp::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Timestamp) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + ::memset(&seconds_, 0, reinterpret_cast<char*>(&nanos_) - reinterpret_cast<char*>(&seconds_) + sizeof(nanos_)); + _internal_metadata_.Clear(); } bool Timestamp::MergePartialFromCodedStream( @@ -232,7 +228,7 @@ bool Timestamp::MergePartialFromCodedStream( // int64 seconds = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>( @@ -246,7 +242,7 @@ bool Timestamp::MergePartialFromCodedStream( // int32 nanos = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -259,12 +255,11 @@ bool Timestamp::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -294,6 +289,10 @@ void Timestamp::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WriteInt32(2, this->nanos(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Timestamp) } @@ -313,6 +312,10 @@ void Timestamp::SerializeWithCachedSizes( target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(2, this->nanos(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Timestamp) return target; } @@ -321,6 +324,11 @@ size_t Timestamp::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Timestamp) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // int64 seconds = 1; if (this->seconds() != 0) { total_size += 1 + @@ -410,9 +418,11 @@ void Timestamp::UnsafeArenaSwap(Timestamp* other) { InternalSwap(other); } void Timestamp::InternalSwap(Timestamp* other) { - std::swap(seconds_, other->seconds_); - std::swap(nanos_, other->nanos_); - std::swap(_cached_size_, other->_cached_size_); + using std::swap; + swap(seconds_, other->seconds_); + swap(nanos_, other->nanos_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Timestamp::GetMetadata() const { diff --git a/src/google/protobuf/timestamp.pb.h b/src/google/protobuf/timestamp.pb.h index 98478540..6668dc64 100644 --- a/src/google/protobuf/timestamp.pb.h +++ b/src/google/protobuf/timestamp.pb.h @@ -48,8 +48,9 @@ struct LIBPROTOBUF_EXPORT TableStruct { static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; static void InitDefaultsImpl(); - static void Shutdown(); }; void LIBPROTOBUF_EXPORT AddDescriptors(); void LIBPROTOBUF_EXPORT InitDefaults(); @@ -68,7 +69,21 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro CopyFrom(from); return *this; } + #if LANG_CXX11 + Timestamp(Timestamp&& from) noexcept + : Timestamp() { + *this = ::std::move(from); + } + inline Timestamp& operator=(Timestamp&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -87,6 +102,9 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro void UnsafeArenaSwap(Timestamp* other); void Swap(Timestamp* other); + friend void swap(Timestamp& a, Timestamp& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -149,7 +167,7 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::int64 seconds_; @@ -163,6 +181,10 @@ class LIBPROTOBUF_EXPORT Timestamp : public ::google::protobuf::Message /* @@pro // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ // Timestamp // int64 seconds = 1; @@ -193,6 +215,9 @@ inline void Timestamp::set_nanos(::google::protobuf::int32 value) { // @@protoc_insertion_point(field_set:google.protobuf.Timestamp.nanos) } +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // @@protoc_insertion_point(namespace_scope) diff --git a/src/google/protobuf/type.pb.cc b/src/google/protobuf/type.pb.cc index 8f017a89..e28cec2e 100644 --- a/src/google/protobuf/type.pb.cc +++ b/src/google/protobuf/type.pb.cc @@ -41,16 +41,16 @@ const ::google::protobuf::EnumDescriptor* file_level_enum_descriptors[3]; } // namespace PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField - const TableStruct::entries[] = { + const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField - const TableStruct::aux[] = { + const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ::google::protobuf::internal::AuxillaryParseTableField(), }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const - TableStruct::schema[] = { + TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, @@ -58,7 +58,7 @@ PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const { NULL, NULL, 0, -1, -1, false }, }; -const ::google::protobuf::uint32 TableStruct::offsets[] = { +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Type, _internal_metadata_), ~0u, // no _extensions_ @@ -111,8 +111,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, name_), GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(Option, value_), }; - -static const ::google::protobuf::internal::MigrationSchema schemas[] = { +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { 0, -1, sizeof(Type)}, { 11, -1, sizeof(Field)}, { 26, -1, sizeof(Enum)}, @@ -150,20 +149,6 @@ void protobuf_RegisterTypes(const ::std::string&) { } } // namespace - -void TableStruct::Shutdown() { - _Type_default_instance_.Shutdown(); - delete file_level_metadata[0].reflection; - _Field_default_instance_.Shutdown(); - delete file_level_metadata[1].reflection; - _Enum_default_instance_.Shutdown(); - delete file_level_metadata[2].reflection; - _EnumValue_default_instance_.Shutdown(); - delete file_level_metadata[3].reflection; - _Option_default_instance_.Shutdown(); - delete file_level_metadata[4].reflection; -} - void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -189,7 +174,7 @@ void InitDefaults() { } void AddDescriptorsImpl() { InitDefaults(); - static const char descriptor[] = { + static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { "\n\032google/protobuf/type.proto\022\017google.pro" "tobuf\032\031google/protobuf/any.proto\032$google" "/protobuf/source_context.proto\"\327\001\n\004Type\022" @@ -237,14 +222,13 @@ void AddDescriptorsImpl() { "google/protobuf/type.proto", &protobuf_RegisterTypes); ::google::protobuf::protobuf_google_2fprotobuf_2fany_2eproto::AddDescriptors(); ::google::protobuf::protobuf_google_2fprotobuf_2fsource_5fcontext_2eproto::AddDescriptors(); - ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); } void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -406,9 +390,7 @@ Type::Type(::google::protobuf::Arena* arena) fields_(arena), oneofs_(arena), options_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Type) @@ -449,14 +431,13 @@ Type::~Type() { void Type::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - if (this != internal_default_instance()) { - delete source_context_; - } + delete source_context_; } void Type::ArenaDtor(void* object) { @@ -486,6 +467,10 @@ Type* Type::New(::google::protobuf::Arena* arena) const { void Type::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Type) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + fields_.Clear(); oneofs_.Clear(); options_.Clear(); @@ -495,6 +480,7 @@ void Type::Clear() { } source_context_ = NULL; syntax_ = 0; + _internal_metadata_.Clear(); } bool Type::MergePartialFromCodedStream( @@ -510,7 +496,7 @@ bool Type::MergePartialFromCodedStream( // string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -526,7 +512,7 @@ bool Type::MergePartialFromCodedStream( // repeated .google.protobuf.Field fields = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_fields())); } else { @@ -538,7 +524,7 @@ bool Type::MergePartialFromCodedStream( // repeated string oneofs = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->add_oneofs())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -555,7 +541,7 @@ bool Type::MergePartialFromCodedStream( // repeated .google.protobuf.Option options = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(34u)) { + static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_options())); } else { @@ -567,7 +553,7 @@ bool Type::MergePartialFromCodedStream( // .google.protobuf.SourceContext source_context = 5; case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(42u)) { + static_cast< ::google::protobuf::uint8>(42u /* 42 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_source_context())); } else { @@ -579,7 +565,7 @@ bool Type::MergePartialFromCodedStream( // .google.protobuf.Syntax syntax = 6; case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(48u)) { + static_cast< ::google::protobuf::uint8>(48u /* 48 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -593,12 +579,11 @@ bool Type::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -662,6 +647,10 @@ void Type::SerializeWithCachedSizes( 6, this->syntax(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Type) } @@ -719,6 +708,10 @@ void Type::SerializeWithCachedSizes( 6, this->syntax(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Type) return target; } @@ -727,6 +720,11 @@ size_t Type::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Type) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // repeated .google.protobuf.Field fields = 2; { unsigned int count = this->fields_size(); @@ -858,13 +856,15 @@ void Type::UnsafeArenaSwap(Type* other) { InternalSwap(other); } void Type::InternalSwap(Type* other) { + using std::swap; fields_.InternalSwap(&other->fields_); oneofs_.InternalSwap(&other->oneofs_); options_.InternalSwap(&other->options_); name_.Swap(&other->name_); - std::swap(source_context_, other->source_context_); - std::swap(syntax_, other->syntax_); - std::swap(_cached_size_, other->_cached_size_); + swap(source_context_, other->source_context_); + swap(syntax_, other->syntax_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Type::GetMetadata() const { @@ -888,6 +888,14 @@ void Type::set_name(const ::std::string& value) { name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Type.name) } +#if LANG_CXX11 +void Type::set_name(::std::string&& value) { + + name_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Type.name) +} +#endif void Type::set_name(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -1080,9 +1088,10 @@ void Type::clear_source_context() { source_context_ = NULL; } const ::google::protobuf::SourceContext& Type::source_context() const { + const ::google::protobuf::SourceContext* p = source_context_; // @@protoc_insertion_point(field_get:google.protobuf.Type.source_context) - return source_context_ != NULL ? *source_context_ - : *::google::protobuf::SourceContext::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceContext*>( + &::google::protobuf::_SourceContext_default_instance_); } ::google::protobuf::SourceContext* Type::mutable_source_context() { @@ -1165,9 +1174,7 @@ Field::Field(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena), options_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Field) @@ -1221,6 +1228,7 @@ Field::~Field() { void Field::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -1258,6 +1266,10 @@ Field* Field::New(::google::protobuf::Arena* arena) const { void Field::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Field) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + options_.Clear(); name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); type_url_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); @@ -1265,6 +1277,7 @@ void Field::Clear() { default_value_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); ::memset(&kind_, 0, reinterpret_cast<char*>(&packed_) - reinterpret_cast<char*>(&kind_) + sizeof(packed_)); + _internal_metadata_.Clear(); } bool Field::MergePartialFromCodedStream( @@ -1280,7 +1293,7 @@ bool Field::MergePartialFromCodedStream( // .google.protobuf.Field.Kind kind = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -1295,7 +1308,7 @@ bool Field::MergePartialFromCodedStream( // .google.protobuf.Field.Cardinality cardinality = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -1310,7 +1323,7 @@ bool Field::MergePartialFromCodedStream( // int32 number = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(24u)) { + static_cast< ::google::protobuf::uint8>(24u /* 24 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -1324,7 +1337,7 @@ bool Field::MergePartialFromCodedStream( // string name = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(34u)) { + static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1340,7 +1353,7 @@ bool Field::MergePartialFromCodedStream( // string type_url = 6; case 6: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(50u)) { + static_cast< ::google::protobuf::uint8>(50u /* 50 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_type_url())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1356,7 +1369,7 @@ bool Field::MergePartialFromCodedStream( // int32 oneof_index = 7; case 7: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(56u)) { + static_cast< ::google::protobuf::uint8>(56u /* 56 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -1370,7 +1383,7 @@ bool Field::MergePartialFromCodedStream( // bool packed = 8; case 8: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(64u)) { + static_cast< ::google::protobuf::uint8>(64u /* 64 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -1384,7 +1397,7 @@ bool Field::MergePartialFromCodedStream( // repeated .google.protobuf.Option options = 9; case 9: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(74u)) { + static_cast< ::google::protobuf::uint8>(74u /* 74 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_options())); } else { @@ -1396,7 +1409,7 @@ bool Field::MergePartialFromCodedStream( // string json_name = 10; case 10: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(82u)) { + static_cast< ::google::protobuf::uint8>(82u /* 82 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_json_name())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1412,7 +1425,7 @@ bool Field::MergePartialFromCodedStream( // string default_value = 11; case 11: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(90u)) { + static_cast< ::google::protobuf::uint8>(90u /* 90 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_default_value())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -1427,12 +1440,11 @@ bool Field::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -1525,6 +1537,10 @@ void Field::SerializeWithCachedSizes( 11, this->default_value(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Field) } @@ -1612,6 +1628,10 @@ void Field::SerializeWithCachedSizes( 11, this->default_value(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Field) return target; } @@ -1620,6 +1640,11 @@ size_t Field::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Field) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // repeated .google.protobuf.Option options = 9; { unsigned int count = this->options_size(); @@ -1787,17 +1812,19 @@ void Field::UnsafeArenaSwap(Field* other) { InternalSwap(other); } void Field::InternalSwap(Field* other) { + using std::swap; options_.InternalSwap(&other->options_); name_.Swap(&other->name_); type_url_.Swap(&other->type_url_); json_name_.Swap(&other->json_name_); default_value_.Swap(&other->default_value_); - std::swap(kind_, other->kind_); - std::swap(cardinality_, other->cardinality_); - std::swap(number_, other->number_); - std::swap(oneof_index_, other->oneof_index_); - std::swap(packed_, other->packed_); - std::swap(_cached_size_, other->_cached_size_); + swap(kind_, other->kind_); + swap(cardinality_, other->cardinality_); + swap(number_, other->number_); + swap(oneof_index_, other->oneof_index_); + swap(packed_, other->packed_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Field::GetMetadata() const { @@ -1863,6 +1890,14 @@ void Field::set_name(const ::std::string& value) { name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Field.name) } +#if LANG_CXX11 +void Field::set_name(::std::string&& value) { + + name_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Field.name) +} +#endif void Field::set_name(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -1930,6 +1965,14 @@ void Field::set_type_url(const ::std::string& value) { type_url_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Field.type_url) } +#if LANG_CXX11 +void Field::set_type_url(::std::string&& value) { + + type_url_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Field.type_url) +} +#endif void Field::set_type_url(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -2055,6 +2098,14 @@ void Field::set_json_name(const ::std::string& value) { json_name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Field.json_name) } +#if LANG_CXX11 +void Field::set_json_name(::std::string&& value) { + + json_name_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Field.json_name) +} +#endif void Field::set_json_name(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -2122,6 +2173,14 @@ void Field::set_default_value(const ::std::string& value) { default_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Field.default_value) } +#if LANG_CXX11 +void Field::set_default_value(::std::string&& value) { + + default_value_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Field.default_value) +} +#endif void Field::set_default_value(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -2234,9 +2293,7 @@ Enum::Enum(::google::protobuf::Arena* arena) _internal_metadata_(arena), enumvalue_(arena), options_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Enum) @@ -2276,14 +2333,13 @@ Enum::~Enum() { void Enum::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - if (this != internal_default_instance()) { - delete source_context_; - } + delete source_context_; } void Enum::ArenaDtor(void* object) { @@ -2313,6 +2369,10 @@ Enum* Enum::New(::google::protobuf::Arena* arena) const { void Enum::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Enum) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + enumvalue_.Clear(); options_.Clear(); name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); @@ -2321,6 +2381,7 @@ void Enum::Clear() { } source_context_ = NULL; syntax_ = 0; + _internal_metadata_.Clear(); } bool Enum::MergePartialFromCodedStream( @@ -2336,7 +2397,7 @@ bool Enum::MergePartialFromCodedStream( // string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -2352,7 +2413,7 @@ bool Enum::MergePartialFromCodedStream( // repeated .google.protobuf.EnumValue enumvalue = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_enumvalue())); } else { @@ -2364,7 +2425,7 @@ bool Enum::MergePartialFromCodedStream( // repeated .google.protobuf.Option options = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_options())); } else { @@ -2376,7 +2437,7 @@ bool Enum::MergePartialFromCodedStream( // .google.protobuf.SourceContext source_context = 4; case 4: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(34u)) { + static_cast< ::google::protobuf::uint8>(34u /* 34 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_source_context())); } else { @@ -2388,7 +2449,7 @@ bool Enum::MergePartialFromCodedStream( // .google.protobuf.Syntax syntax = 5; case 5: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(40u)) { + static_cast< ::google::protobuf::uint8>(40u /* 40 & 0xFF */)) { int value; DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< int, ::google::protobuf::internal::WireFormatLite::TYPE_ENUM>( @@ -2402,12 +2463,11 @@ bool Enum::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -2461,6 +2521,10 @@ void Enum::SerializeWithCachedSizes( 5, this->syntax(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Enum) } @@ -2508,6 +2572,10 @@ void Enum::SerializeWithCachedSizes( 5, this->syntax(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Enum) return target; } @@ -2516,6 +2584,11 @@ size_t Enum::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Enum) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // repeated .google.protobuf.EnumValue enumvalue = 2; { unsigned int count = this->enumvalue_size(); @@ -2638,12 +2711,14 @@ void Enum::UnsafeArenaSwap(Enum* other) { InternalSwap(other); } void Enum::InternalSwap(Enum* other) { + using std::swap; enumvalue_.InternalSwap(&other->enumvalue_); options_.InternalSwap(&other->options_); name_.Swap(&other->name_); - std::swap(source_context_, other->source_context_); - std::swap(syntax_, other->syntax_); - std::swap(_cached_size_, other->_cached_size_); + swap(source_context_, other->source_context_); + swap(syntax_, other->syntax_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Enum::GetMetadata() const { @@ -2667,6 +2742,14 @@ void Enum::set_name(const ::std::string& value) { name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Enum.name) } +#if LANG_CXX11 +void Enum::set_name(::std::string&& value) { + + name_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Enum.name) +} +#endif void Enum::set_name(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -2790,9 +2873,10 @@ void Enum::clear_source_context() { source_context_ = NULL; } const ::google::protobuf::SourceContext& Enum::source_context() const { + const ::google::protobuf::SourceContext* p = source_context_; // @@protoc_insertion_point(field_get:google.protobuf.Enum.source_context) - return source_context_ != NULL ? *source_context_ - : *::google::protobuf::SourceContext::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceContext*>( + &::google::protobuf::_SourceContext_default_instance_); } ::google::protobuf::SourceContext* Enum::mutable_source_context() { @@ -2868,9 +2952,7 @@ EnumValue::EnumValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena), options_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.EnumValue) @@ -2903,6 +2985,7 @@ EnumValue::~EnumValue() { void EnumValue::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -2937,9 +3020,14 @@ EnumValue* EnumValue::New(::google::protobuf::Arena* arena) const { void EnumValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.EnumValue) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + options_.Clear(); name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); number_ = 0; + _internal_metadata_.Clear(); } bool EnumValue::MergePartialFromCodedStream( @@ -2955,7 +3043,7 @@ bool EnumValue::MergePartialFromCodedStream( // string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -2971,7 +3059,7 @@ bool EnumValue::MergePartialFromCodedStream( // int32 number = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(16u)) { + static_cast< ::google::protobuf::uint8>(16u /* 16 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -2985,7 +3073,7 @@ bool EnumValue::MergePartialFromCodedStream( // repeated .google.protobuf.Option options = 3; case 3: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(26u)) { + static_cast< ::google::protobuf::uint8>(26u /* 26 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, add_options())); } else { @@ -2996,12 +3084,11 @@ bool EnumValue::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -3042,6 +3129,10 @@ void EnumValue::SerializeWithCachedSizes( 3, this->options(i), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.EnumValue) } @@ -3074,6 +3165,10 @@ void EnumValue::SerializeWithCachedSizes( 3, this->options(i), deterministic, target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.EnumValue) return target; } @@ -3082,6 +3177,11 @@ size_t EnumValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.EnumValue) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // repeated .google.protobuf.Option options = 3; { unsigned int count = this->options_size(); @@ -3183,10 +3283,12 @@ void EnumValue::UnsafeArenaSwap(EnumValue* other) { InternalSwap(other); } void EnumValue::InternalSwap(EnumValue* other) { + using std::swap; options_.InternalSwap(&other->options_); name_.Swap(&other->name_); - std::swap(number_, other->number_); - std::swap(_cached_size_, other->_cached_size_); + swap(number_, other->number_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata EnumValue::GetMetadata() const { @@ -3210,6 +3312,14 @@ void EnumValue::set_name(const ::std::string& value) { name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.EnumValue.name) } +#if LANG_CXX11 +void EnumValue::set_name(::std::string&& value) { + + name_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.EnumValue.name) +} +#endif void EnumValue::set_name(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -3361,9 +3471,7 @@ Option::Option() Option::Option(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2ftype_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Option) @@ -3399,14 +3507,13 @@ Option::~Option() { void Option::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } name_.Destroy(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), arena); - if (this != internal_default_instance()) { - delete value_; - } + delete value_; } void Option::ArenaDtor(void* object) { @@ -3436,11 +3543,16 @@ Option* Option::New(::google::protobuf::Arena* arena) const { void Option::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Option) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + name_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); if (GetArenaNoVirtual() == NULL && value_ != NULL) { delete value_; } value_ = NULL; + _internal_metadata_.Clear(); } bool Option::MergePartialFromCodedStream( @@ -3456,7 +3568,7 @@ bool Option::MergePartialFromCodedStream( // string name = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_name())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -3472,7 +3584,7 @@ bool Option::MergePartialFromCodedStream( // .google.protobuf.Any value = 2; case 2: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(18u)) { + static_cast< ::google::protobuf::uint8>(18u /* 18 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadMessageNoVirtual( input, mutable_value())); } else { @@ -3483,12 +3595,11 @@ bool Option::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -3524,6 +3635,10 @@ void Option::SerializeWithCachedSizes( 2, *this->value_, output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Option) } @@ -3551,6 +3666,10 @@ void Option::SerializeWithCachedSizes( 2, *this->value_, deterministic, target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Option) return target; } @@ -3559,6 +3678,11 @@ size_t Option::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Option) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // string name = 1; if (this->name().size() > 0) { total_size += 1 + @@ -3648,9 +3772,11 @@ void Option::UnsafeArenaSwap(Option* other) { InternalSwap(other); } void Option::InternalSwap(Option* other) { + using std::swap; name_.Swap(&other->name_); - std::swap(value_, other->value_); - std::swap(_cached_size_, other->_cached_size_); + swap(value_, other->value_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Option::GetMetadata() const { @@ -3674,6 +3800,14 @@ void Option::set_name(const ::std::string& value) { name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Option.name) } +#if LANG_CXX11 +void Option::set_name(::std::string&& value) { + + name_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Option.name) +} +#endif void Option::set_name(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -3737,9 +3871,10 @@ void Option::clear_value() { value_ = NULL; } const ::google::protobuf::Any& Option::value() const { + const ::google::protobuf::Any* p = value_; // @@protoc_insertion_point(field_get:google.protobuf.Option.value) - return value_ != NULL ? *value_ - : *::google::protobuf::Any::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::Any*>( + &::google::protobuf::_Any_default_instance_); } ::google::protobuf::Any* Option::mutable_value() { diff --git a/src/google/protobuf/type.pb.h b/src/google/protobuf/type.pb.h index c1cd4164..cffa9985 100644 --- a/src/google/protobuf/type.pb.h +++ b/src/google/protobuf/type.pb.h @@ -35,9 +35,6 @@ // @@protoc_insertion_point(includes) namespace google { namespace protobuf { -class Any; -class AnyDefaultTypeInternal; -LIBPROTOBUF_EXPORT extern AnyDefaultTypeInternal _Any_default_instance_; class Enum; class EnumDefaultTypeInternal; LIBPROTOBUF_EXPORT extern EnumDefaultTypeInternal _Enum_default_instance_; @@ -50,9 +47,6 @@ LIBPROTOBUF_EXPORT extern FieldDefaultTypeInternal _Field_default_instance_; class Option; class OptionDefaultTypeInternal; LIBPROTOBUF_EXPORT extern OptionDefaultTypeInternal _Option_default_instance_; -class SourceContext; -class SourceContextDefaultTypeInternal; -LIBPROTOBUF_EXPORT extern SourceContextDefaultTypeInternal _SourceContext_default_instance_; class Type; class TypeDefaultTypeInternal; LIBPROTOBUF_EXPORT extern TypeDefaultTypeInternal _Type_default_instance_; @@ -69,8 +63,9 @@ struct LIBPROTOBUF_EXPORT TableStruct { static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; static void InitDefaultsImpl(); - static void Shutdown(); }; void LIBPROTOBUF_EXPORT AddDescriptors(); void LIBPROTOBUF_EXPORT InitDefaults(); @@ -171,7 +166,21 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i CopyFrom(from); return *this; } + #if LANG_CXX11 + Type(Type&& from) noexcept + : Type() { + *this = ::std::move(from); + } + inline Type& operator=(Type&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -190,6 +199,9 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i void UnsafeArenaSwap(Type* other); void Swap(Type* other); + friend void swap(Type& a, Type& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -287,6 +299,9 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i static const int kNameFieldNumber = 1; const ::std::string& name() const; void set_name(const ::std::string& value); + #if LANG_CXX11 + void set_name(::std::string&& value); + #endif void set_name(const char* value); void set_name(const char* value, size_t size); ::std::string* mutable_name(); @@ -322,7 +337,7 @@ class LIBPROTOBUF_EXPORT Type : public ::google::protobuf::Message /* @@protoc_i private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::Field > fields_; @@ -347,7 +362,21 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ CopyFrom(from); return *this; } + #if LANG_CXX11 + Field(Field&& from) noexcept + : Field() { + *this = ::std::move(from); + } + inline Field& operator=(Field&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -366,6 +395,9 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ void UnsafeArenaSwap(Field* other); void Swap(Field* other); + friend void swap(Field& a, Field& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -519,6 +551,9 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ static const int kNameFieldNumber = 4; const ::std::string& name() const; void set_name(const ::std::string& value); + #if LANG_CXX11 + void set_name(::std::string&& value); + #endif void set_name(const char* value); void set_name(const char* value, size_t size); ::std::string* mutable_name(); @@ -533,6 +568,9 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ static const int kTypeUrlFieldNumber = 6; const ::std::string& type_url() const; void set_type_url(const ::std::string& value); + #if LANG_CXX11 + void set_type_url(::std::string&& value); + #endif void set_type_url(const char* value); void set_type_url(const char* value, size_t size); ::std::string* mutable_type_url(); @@ -547,6 +585,9 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ static const int kJsonNameFieldNumber = 10; const ::std::string& json_name() const; void set_json_name(const ::std::string& value); + #if LANG_CXX11 + void set_json_name(::std::string&& value); + #endif void set_json_name(const char* value); void set_json_name(const char* value, size_t size); ::std::string* mutable_json_name(); @@ -561,6 +602,9 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ static const int kDefaultValueFieldNumber = 11; const ::std::string& default_value() const; void set_default_value(const ::std::string& value); + #if LANG_CXX11 + void set_default_value(::std::string&& value); + #endif void set_default_value(const char* value); void set_default_value(const char* value, size_t size); ::std::string* mutable_default_value(); @@ -604,7 +648,7 @@ class LIBPROTOBUF_EXPORT Field : public ::google::protobuf::Message /* @@protoc_ private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_; @@ -633,7 +677,21 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i CopyFrom(from); return *this; } + #if LANG_CXX11 + Enum(Enum&& from) noexcept + : Enum() { + *this = ::std::move(from); + } + inline Enum& operator=(Enum&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -652,6 +710,9 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i void UnsafeArenaSwap(Enum* other); void Swap(Enum* other); + friend void swap(Enum& a, Enum& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -727,6 +788,9 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i static const int kNameFieldNumber = 1; const ::std::string& name() const; void set_name(const ::std::string& value); + #if LANG_CXX11 + void set_name(::std::string&& value); + #endif void set_name(const char* value); void set_name(const char* value, size_t size); ::std::string* mutable_name(); @@ -762,7 +826,7 @@ class LIBPROTOBUF_EXPORT Enum : public ::google::protobuf::Message /* @@protoc_i private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::EnumValue > enumvalue_; @@ -786,7 +850,21 @@ class LIBPROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@pro CopyFrom(from); return *this; } + #if LANG_CXX11 + EnumValue(EnumValue&& from) noexcept + : EnumValue() { + *this = ::std::move(from); + } + inline EnumValue& operator=(EnumValue&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -805,6 +883,9 @@ class LIBPROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@pro void UnsafeArenaSwap(EnumValue* other); void Swap(EnumValue* other); + friend void swap(EnumValue& a, EnumValue& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -868,6 +949,9 @@ class LIBPROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@pro static const int kNameFieldNumber = 1; const ::std::string& name() const; void set_name(const ::std::string& value); + #if LANG_CXX11 + void set_name(::std::string&& value); + #endif void set_name(const char* value); void set_name(const char* value, size_t size); ::std::string* mutable_name(); @@ -887,7 +971,7 @@ class LIBPROTOBUF_EXPORT EnumValue : public ::google::protobuf::Message /* @@pro private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::RepeatedPtrField< ::google::protobuf::Option > options_; @@ -909,7 +993,21 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc CopyFrom(from); return *this; } + #if LANG_CXX11 + Option(Option&& from) noexcept + : Option() { + *this = ::std::move(from); + } + inline Option& operator=(Option&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -928,6 +1026,9 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc void UnsafeArenaSwap(Option* other); void Swap(Option* other); + friend void swap(Option& a, Option& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -979,6 +1080,9 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc static const int kNameFieldNumber = 1; const ::std::string& name() const; void set_name(const ::std::string& value); + #if LANG_CXX11 + void set_name(::std::string&& value); + #endif void set_name(const char* value); void set_name(const char* value, size_t size); ::std::string* mutable_name(); @@ -1008,7 +1112,7 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::internal::ArenaStringPtr name_; @@ -1022,6 +1126,10 @@ class LIBPROTOBUF_EXPORT Option : public ::google::protobuf::Message /* @@protoc // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ // Type // string name = 1; @@ -1037,6 +1145,14 @@ inline void Type::set_name(const ::std::string& value) { name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Type.name) } +#if LANG_CXX11 +inline void Type::set_name(::std::string&& value) { + + name_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Type.name) +} +#endif inline void Type::set_name(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -1229,9 +1345,10 @@ inline void Type::clear_source_context() { source_context_ = NULL; } inline const ::google::protobuf::SourceContext& Type::source_context() const { + const ::google::protobuf::SourceContext* p = source_context_; // @@protoc_insertion_point(field_get:google.protobuf.Type.source_context) - return source_context_ != NULL ? *source_context_ - : *::google::protobuf::SourceContext::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceContext*>( + &::google::protobuf::_SourceContext_default_instance_); } inline ::google::protobuf::SourceContext* Type::mutable_source_context() { @@ -1344,6 +1461,14 @@ inline void Field::set_name(const ::std::string& value) { name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Field.name) } +#if LANG_CXX11 +inline void Field::set_name(::std::string&& value) { + + name_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Field.name) +} +#endif inline void Field::set_name(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -1411,6 +1536,14 @@ inline void Field::set_type_url(const ::std::string& value) { type_url_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Field.type_url) } +#if LANG_CXX11 +inline void Field::set_type_url(::std::string&& value) { + + type_url_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Field.type_url) +} +#endif inline void Field::set_type_url(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -1536,6 +1669,14 @@ inline void Field::set_json_name(const ::std::string& value) { json_name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Field.json_name) } +#if LANG_CXX11 +inline void Field::set_json_name(::std::string&& value) { + + json_name_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Field.json_name) +} +#endif inline void Field::set_json_name(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -1603,6 +1744,14 @@ inline void Field::set_default_value(const ::std::string& value) { default_value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Field.default_value) } +#if LANG_CXX11 +inline void Field::set_default_value(::std::string&& value) { + + default_value_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Field.default_value) +} +#endif inline void Field::set_default_value(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -1674,6 +1823,14 @@ inline void Enum::set_name(const ::std::string& value) { name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Enum.name) } +#if LANG_CXX11 +inline void Enum::set_name(::std::string&& value) { + + name_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Enum.name) +} +#endif inline void Enum::set_name(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -1797,9 +1954,10 @@ inline void Enum::clear_source_context() { source_context_ = NULL; } inline const ::google::protobuf::SourceContext& Enum::source_context() const { + const ::google::protobuf::SourceContext* p = source_context_; // @@protoc_insertion_point(field_get:google.protobuf.Enum.source_context) - return source_context_ != NULL ? *source_context_ - : *::google::protobuf::SourceContext::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::SourceContext*>( + &::google::protobuf::_SourceContext_default_instance_); } inline ::google::protobuf::SourceContext* Enum::mutable_source_context() { @@ -1870,6 +2028,14 @@ inline void EnumValue::set_name(const ::std::string& value) { name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.EnumValue.name) } +#if LANG_CXX11 +inline void EnumValue::set_name(::std::string&& value) { + + name_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.EnumValue.name) +} +#endif inline void EnumValue::set_name(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -1985,6 +2151,14 @@ inline void Option::set_name(const ::std::string& value) { name_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.Option.name) } +#if LANG_CXX11 +inline void Option::set_name(::std::string&& value) { + + name_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.Option.name) +} +#endif inline void Option::set_name(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -2048,9 +2222,10 @@ inline void Option::clear_value() { value_ = NULL; } inline const ::google::protobuf::Any& Option::value() const { + const ::google::protobuf::Any* p = value_; // @@protoc_insertion_point(field_get:google.protobuf.Option.value) - return value_ != NULL ? *value_ - : *::google::protobuf::Any::internal_default_instance(); + return p != NULL ? *p : *reinterpret_cast<const ::google::protobuf::Any*>( + &::google::protobuf::_Any_default_instance_); } inline ::google::protobuf::Any* Option::mutable_value() { @@ -2090,6 +2265,9 @@ inline void Option::set_allocated_value(::google::protobuf::Any* value) { // @@protoc_insertion_point(field_set_allocated:google.protobuf.Option.value) } +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // ------------------------------------------------------------------- @@ -2106,7 +2284,6 @@ inline void Option::set_allocated_value(::google::protobuf::Any* value) { } // namespace protobuf } // namespace google -#ifndef SWIG namespace google { namespace protobuf { @@ -2128,7 +2305,6 @@ inline const EnumDescriptor* GetEnumDescriptor< ::google::protobuf::Syntax>() { } // namespace protobuf } // namespace google -#endif // SWIG // @@protoc_insertion_point(global_scope) diff --git a/src/google/protobuf/unittest.proto b/src/google/protobuf/unittest.proto index 2040487e..45a0edad 100644 --- a/src/google/protobuf/unittest.proto +++ b/src/google/protobuf/unittest.proto @@ -397,6 +397,12 @@ message TestRequiredForeign { optional int32 dummy = 3; } +message TestRequiredMessage { + optional TestRequired optional_message = 1; + repeated TestRequired repeated_message = 2; + required TestRequired required_message = 3; +} + // Test that we can use NestedMessage from outside TestAllTypes. message TestForeignNested { optional TestAllTypes.NestedMessage foreign_nested = 1; diff --git a/src/google/protobuf/unittest_lite.proto b/src/google/protobuf/unittest_lite.proto index c39ac6b0..9a15bdaa 100644 --- a/src/google/protobuf/unittest_lite.proto +++ b/src/google/protobuf/unittest_lite.proto @@ -439,3 +439,18 @@ message TestHugeFieldNumbersLite { extend TestHugeFieldNumbersLite { optional TestAllTypesLite test_all_types_lite = 536860000; } + +message TestOneofParsingLite { + oneof oneof_field { + int32 oneof_int32 = 1; + TestAllTypesLite oneof_submessage = 2; + string oneof_string = 3; + bytes oneof_bytes = 4 [default = "default bytes"]; + string oneof_string_cord = 5 [ctype = CORD, default = "default Cord"]; + bytes oneof_bytes_cord = 6 [ctype = CORD]; + string oneof_string_string_piece = 7 [ctype = STRING_PIECE]; + bytes oneof_bytes_string_piece = 8 + [ctype = STRING_PIECE, default = "default StringPiece"]; + V2EnumLite oneof_enum = 9; + } +} diff --git a/src/google/protobuf/unittest_proto3.proto b/src/google/protobuf/unittest_proto3.proto index a27b1b26..84815d42 100644 --- a/src/google/protobuf/unittest_proto3.proto +++ b/src/google/protobuf/unittest_proto3.proto @@ -28,35 +28,13 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// Author: kenton@google.com (Kenton Varda) -// Based on original Protocol Buffers design by -// Sanjay Ghemawat, Jeff Dean, and others. -// -// A proto file we will use for unit testing. - syntax = "proto3"; -// Some generic_services option(s) added automatically. -// See: http://go/proto2-generic-services-default -option cc_generic_services = true; // auto-added -option java_generic_services = true; // auto-added -option py_generic_services = true; // auto-added -option cc_enable_arenas = true; -option csharp_namespace = "Google.Protobuf.TestProtos"; - -import "google/protobuf/unittest_import_proto3.proto"; - -// We don't put this in a package within proto2 because we need to make sure -// that the generated code doesn't depend on being in the proto2 namespace. -// In test_util.h we do "using namespace unittest = protobuf_unittest". -package protobuf_unittest; - -// Protos optimized for SPEED use a strict superset of the generated code -// of equivalent ones optimized for CODE_SIZE, so we should optimize all our -// tests for speed unless explicitly testing code size optimization. option optimize_for = SPEED; -option java_outer_classname = "UnittestProto"; +import "google/protobuf/unittest_import.proto"; + +package proto3_unittest; // This proto includes every type of field in both singular and repeated // forms. @@ -69,7 +47,7 @@ message TestAllTypes { } enum NestedEnum { - NESTED_ENUM_UNSPECIFIED = 0; + ZERO = 0; FOO = 1; BAR = 2; BAZ = 3; @@ -77,33 +55,49 @@ message TestAllTypes { } // Singular - int32 single_int32 = 1; - int64 single_int64 = 2; - uint32 single_uint32 = 3; - uint64 single_uint64 = 4; - sint32 single_sint32 = 5; - sint64 single_sint64 = 6; - fixed32 single_fixed32 = 7; - fixed64 single_fixed64 = 8; - sfixed32 single_sfixed32 = 9; - sfixed64 single_sfixed64 = 10; - float single_float = 11; - double single_double = 12; - bool single_bool = 13; - string single_string = 14; - bytes single_bytes = 15; - - NestedMessage single_nested_message = 18; - ForeignMessage single_foreign_message = 19; - protobuf_unittest_import.ImportMessage single_import_message = 20; - - NestedEnum single_nested_enum = 21; - ForeignEnum single_foreign_enum = 22; - protobuf_unittest_import.ImportEnum single_import_enum = 23; + int32 optional_int32 = 1; + int64 optional_int64 = 2; + uint32 optional_uint32 = 3; + uint64 optional_uint64 = 4; + sint32 optional_sint32 = 5; + sint64 optional_sint64 = 6; + fixed32 optional_fixed32 = 7; + fixed64 optional_fixed64 = 8; + sfixed32 optional_sfixed32 = 9; + sfixed64 optional_sfixed64 = 10; + float optional_float = 11; + double optional_double = 12; + bool optional_bool = 13; + string optional_string = 14; + bytes optional_bytes = 15; + + // Groups are not allowed in proto3. + // optional group OptionalGroup = 16 { + // optional int32 a = 17; + // } + + NestedMessage optional_nested_message = 18; + ForeignMessage optional_foreign_message = 19; + protobuf_unittest_import.ImportMessage optional_import_message = 20; + + NestedEnum optional_nested_enum = 21; + ForeignEnum optional_foreign_enum = 22; + + // Omitted (compared to unittest.proto) because proto2 enums are not allowed + // inside proto2 messages. + // + // optional protobuf_unittest_import.ImportEnum optional_import_enum = 23; + + string optional_string_piece = 24 [ctype=STRING_PIECE]; + string optional_cord = 25 [ctype=CORD]; // Defined in unittest_import_public.proto protobuf_unittest_import.PublicImportMessage - single_public_import_message = 26; + optional_public_import_message = 26; + + NestedMessage optional_lazy_message = 27 [lazy=true]; + protobuf_unittest_import.ImportMessage optional_lazy_import_message = 115 + [lazy = true]; // Repeated repeated int32 repeated_int32 = 31; @@ -122,18 +116,28 @@ message TestAllTypes { repeated string repeated_string = 44; repeated bytes repeated_bytes = 45; + // Groups are not allowed in proto3. + // repeated group RepeatedGroup = 46 { + // optional int32 a = 47; + // } + repeated NestedMessage repeated_nested_message = 48; repeated ForeignMessage repeated_foreign_message = 49; repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50; repeated NestedEnum repeated_nested_enum = 51; repeated ForeignEnum repeated_foreign_enum = 52; - repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53; - // Defined in unittest_import_public.proto - repeated protobuf_unittest_import.PublicImportMessage - repeated_public_import_message = 54; - // For oneof test + // Omitted (compared to unittest.proto) because proto2 enums are not allowed + // inside proto2 messages. + // + // repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53; + + repeated string repeated_string_piece = 54 [ctype=STRING_PIECE]; + repeated string repeated_cord = 55 [ctype=CORD]; + + repeated NestedMessage repeated_lazy_message = 57 [lazy=true]; + oneof oneof_field { uint32 oneof_uint32 = 111; NestedMessage oneof_nested_message = 112; @@ -142,176 +146,6 @@ message TestAllTypes { } } -// This proto includes a recusively nested message. -message NestedTestAllTypes { - NestedTestAllTypes child = 1; - TestAllTypes payload = 2; - repeated NestedTestAllTypes repeated_child = 3; -} - -message TestDeprecatedFields { - int32 deprecated_int32 = 1 [deprecated=true]; -} - -// Define these after TestAllTypes to make sure the compiler can handle -// that. -message ForeignMessage { - int32 c = 1; -} - -enum ForeignEnum { - FOREIGN_UNSPECIFIED = 0; - FOREIGN_FOO = 4; - FOREIGN_BAR = 5; - FOREIGN_BAZ = 6; -} - -message TestReservedFields { - reserved 2, 15, 9 to 11; - reserved "bar", "baz"; -} - - -// Test that we can use NestedMessage from outside TestAllTypes. -message TestForeignNested { - TestAllTypes.NestedMessage foreign_nested = 1; -} - -// Test that really large tag numbers don't break anything. -message TestReallyLargeTagNumber { - // The largest possible tag number is 2^28 - 1, since the wire format uses - // three bits to communicate wire type. - int32 a = 1; - int32 bb = 268435455; -} - -message TestRecursiveMessage { - TestRecursiveMessage a = 1; - int32 i = 2; -} - -// Test that mutual recursion works. -message TestMutualRecursionA { - TestMutualRecursionB bb = 1; -} - -message TestMutualRecursionB { - TestMutualRecursionA a = 1; - int32 optional_int32 = 2; -} - -message TestEnumAllowAlias { - TestEnumWithDupValue value = 1; -} - -// Test an enum that has multiple values with the same number. -enum TestEnumWithDupValue { - TEST_ENUM_WITH_DUP_VALUE_UNSPECIFIED = 0; - option allow_alias = true; - - FOO1 = 1; - BAR1 = 2; - BAZ = 3; - FOO2 = 1; - BAR2 = 2; -} - -// Test an enum with large, unordered values. -enum TestSparseEnum { - TEST_SPARSE_ENUM_UNSPECIFIED = 0; - SPARSE_A = 123; - SPARSE_B = 62374; - SPARSE_C = 12589234; - SPARSE_D = -15; - SPARSE_E = -53452; - // In proto3, value 0 must be the first one specified - // SPARSE_F = 0; - SPARSE_G = 2; -} - -// Test message with CamelCase field names. This violates Protocol Buffer -// standard style. -message TestCamelCaseFieldNames { - int32 PrimitiveField = 1; - string StringField = 2; - ForeignEnum EnumField = 3; - ForeignMessage MessageField = 4; - - repeated int32 RepeatedPrimitiveField = 7; - repeated string RepeatedStringField = 8; - repeated ForeignEnum RepeatedEnumField = 9; - repeated ForeignMessage RepeatedMessageField = 10; -} - - -// We list fields out of order, to ensure that we're using field number and not -// field index to determine serialization order. -message TestFieldOrderings { - string my_string = 11; - int64 my_int = 1; - float my_float = 101; - message NestedMessage { - int64 oo = 2; - // The field name "b" fails to compile in proto1 because it conflicts with - // a local variable named "b" in one of the generated methods. Doh. - // This file needs to compile in proto1 to test backwards-compatibility. - int32 bb = 1; - } - - NestedMessage single_nested_message = 200; -} - -message SparseEnumMessage { - TestSparseEnum sparse_enum = 1; -} - -// Test String and Bytes: string is for valid UTF-8 strings -message OneString { - string data = 1; -} - -message MoreString { - repeated string data = 1; -} - -message OneBytes { - bytes data = 1; -} - -message MoreBytes { - bytes data = 1; -} - -// Test int32, uint32, int64, uint64, and bool are all compatible -message Int32Message { - int32 data = 1; -} - -message Uint32Message { - uint32 data = 1; -} - -message Int64Message { - int64 data = 1; -} - -message Uint64Message { - uint64 data = 1; -} - -message BoolMessage { - bool data = 1; -} - -// Test oneofs. -message TestOneof { - oneof foo { - int32 foo_int = 1; - string foo_string = 2; - TestAllTypes foo_message = 3; - } -} - // Test messages for packed fields message TestPackedTypes { @@ -331,61 +165,44 @@ message TestPackedTypes { repeated ForeignEnum packed_enum = 103 [packed = true]; } -// A message with the same fields as TestPackedTypes, but without packing. Used -// to test packed <-> unpacked wire compatibility. +// Explicitly set packed to false message TestUnpackedTypes { - repeated int32 unpacked_int32 = 90 [packed = false]; - repeated int64 unpacked_int64 = 91 [packed = false]; - repeated uint32 unpacked_uint32 = 92 [packed = false]; - repeated uint64 unpacked_uint64 = 93 [packed = false]; - repeated sint32 unpacked_sint32 = 94 [packed = false]; - repeated sint64 unpacked_sint64 = 95 [packed = false]; - repeated fixed32 unpacked_fixed32 = 96 [packed = false]; - repeated fixed64 unpacked_fixed64 = 97 [packed = false]; - repeated sfixed32 unpacked_sfixed32 = 98 [packed = false]; - repeated sfixed64 unpacked_sfixed64 = 99 [packed = false]; - repeated float unpacked_float = 100 [packed = false]; - repeated double unpacked_double = 101 [packed = false]; - repeated bool unpacked_bool = 102 [packed = false]; - repeated ForeignEnum unpacked_enum = 103 [packed = false]; + repeated int32 repeated_int32 = 1 [packed = false]; + repeated int64 repeated_int64 = 2 [packed = false]; + repeated uint32 repeated_uint32 = 3 [packed = false]; + repeated uint64 repeated_uint64 = 4 [packed = false]; + repeated sint32 repeated_sint32 = 5 [packed = false]; + repeated sint64 repeated_sint64 = 6 [packed = false]; + repeated fixed32 repeated_fixed32 = 7 [packed = false]; + repeated fixed64 repeated_fixed64 = 8 [packed = false]; + repeated sfixed32 repeated_sfixed32 = 9 [packed = false]; + repeated sfixed64 repeated_sfixed64 = 10 [packed = false]; + repeated float repeated_float = 11 [packed = false]; + repeated double repeated_double = 12 [packed = false]; + repeated bool repeated_bool = 13 [packed = false]; + repeated TestAllTypes.NestedEnum repeated_nested_enum = 14 [packed = false]; } -message TestRepeatedScalarDifferentTagSizes { - // Parsing repeated fixed size values used to fail. This message needs to be - // used in order to get a tag of the right size; all of the repeated fields - // in TestAllTypes didn't trigger the check. - repeated fixed32 repeated_fixed32 = 12; - // Check for a varint type, just for good measure. - repeated int32 repeated_int32 = 13; - - // These have two-byte tags. - repeated fixed64 repeated_fixed64 = 2046; - repeated int64 repeated_int64 = 2047; - - // Three byte tags. - repeated float repeated_float = 262142; - repeated uint64 repeated_uint64 = 262143; +// This proto includes a recusively nested message. +message NestedTestAllTypes { + NestedTestAllTypes child = 1; + TestAllTypes payload = 2; } -message TestCommentInjectionMessage { - // */ <- This should not close the generated doc comment - string a = 1; +// Define these after TestAllTypes to make sure the compiler can handle +// that. +message ForeignMessage { + int32 c = 1; } - -// Test that RPC services work. -message FooRequest {} -message FooResponse {} - -message FooClientMessage {} -message FooServerMessage{} - -service TestService { - rpc Foo(FooRequest) returns (FooResponse); - rpc Bar(BarRequest) returns (BarResponse); +enum ForeignEnum { + FOREIGN_ZERO = 0; + FOREIGN_FOO = 4; + FOREIGN_BAR = 5; + FOREIGN_BAZ = 6; } - -message BarRequest {} -message BarResponse {} +// TestEmptyMessage is used to test behavior of unknown fields. +message TestEmptyMessage { +} diff --git a/src/google/protobuf/util/field_comparator.h b/src/google/protobuf/util/field_comparator.h index ad560ebc..26a7ba4d 100644 --- a/src/google/protobuf/util/field_comparator.h +++ b/src/google/protobuf/util/field_comparator.h @@ -237,7 +237,7 @@ class LIBPROTOBUF_EXPORT DefaultFieldComparator : public FieldComparator { // True iff default_tolerance_ has been explicitly set. // - // If false, then the default tolerance for flaots and doubles is that which + // If false, then the default tolerance for floats and doubles is that which // is used by MathUtil::AlmostEquals(). bool has_default_tolerance_; diff --git a/src/google/protobuf/util/field_mask_util.cc b/src/google/protobuf/util/field_mask_util.cc index 85cecec5..982d6407 100644 --- a/src/google/protobuf/util/field_mask_util.cc +++ b/src/google/protobuf/util/field_mask_util.cc @@ -207,6 +207,18 @@ class FieldMaskTree { MergeMessage(&root_, source, options, destination); } + // Add required field path of the message to this tree based on current tree + // structure. If a message is present in the tree, add the path of its + // required field to the tree. This is to make sure that after trimming a + // message with required fields are set, check IsInitialized() will not fail. + void AddRequiredFieldPath(const Descriptor* descriptor) { + // Do nothing if the tree is empty. + if (root_.children.empty()) { + return; + } + AddRequiredFieldPath(&root_, descriptor); + } + // Trims all fields not specified by this tree from the given message. void TrimMessage(Message* message) { // Do nothing if the tree is empty. @@ -249,6 +261,12 @@ class FieldMaskTree { const FieldMaskUtil::MergeOptions& options, Message* destination); + // Add required field path of the message to this tree based on current tree + // structure. If a message is present in the tree, add the path of its + // required field to the tree. This is to make sure that after trimming a + // message with required fields are set, check IsInitialized() will not fail. + void AddRequiredFieldPath(Node* node, const Descriptor* descriptor); + // Trims all fields not specified by this sub-tree from the given message. void TrimMessage(const Node* node, Message* message); @@ -456,6 +474,41 @@ void FieldMaskTree::MergeMessage(const Node* node, const Message& source, } } +void FieldMaskTree::AddRequiredFieldPath( + Node* node, const Descriptor* descriptor) { + const int32 field_count = descriptor->field_count(); + for (int index = 0; index < field_count; ++index) { + const FieldDescriptor* field = descriptor->field(index); + if (field->is_required()) { + const string& node_name = field->name(); + Node*& child = node->children[node_name]; + if (child == NULL) { + // Add required field path to the tree + child = new Node(); + } else if (child->children.empty()){ + // If the required field is in the tree and does not have any children, + // do nothing. + continue; + } + // Add required field in the children to the tree if the field is message. + if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { + AddRequiredFieldPath(child, field->message_type()); + } + } else if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { + std::map<string, Node*>::const_iterator it = + node->children.find(field->name()); + if (it != node->children.end()) { + // Add required fields in the children to the + // tree if the field is a message and present in the tree. + Node* child = it->second; + if (!child->children.empty()) { + AddRequiredFieldPath(child, field->message_type()); + } + } + } + } +} + void FieldMaskTree::TrimMessage(const Node* node, Message* message) { GOOGLE_DCHECK(!node->children.empty()); const Reflection* reflection = message->GetReflection(); @@ -470,7 +523,7 @@ void FieldMaskTree::TrimMessage(const Node* node, Message* message) { } else { if (field->cpp_type() == FieldDescriptor::CPPTYPE_MESSAGE) { Node* child = it->second; - if (!child->children.empty()) { + if (!child->children.empty() && reflection->HasField(*message, field)) { TrimMessage(child, reflection->MutableMessage(message, field)); } } @@ -542,6 +595,20 @@ void FieldMaskUtil::TrimMessage(const FieldMask& mask, Message* destination) { tree.TrimMessage(GOOGLE_CHECK_NOTNULL(destination)); } +void FieldMaskUtil::TrimMessage(const FieldMask& mask, Message* destination, + const TrimOptions& options) { + // Build a FieldMaskTree and walk through the tree to merge all specified + // fields. + FieldMaskTree tree; + tree.MergeFromFieldMask(mask); + // If keep_required_fields is true, implicitely add required fields of + // a message present in the tree to prevent from trimming. + if (options.keep_required_fields()) { + tree.AddRequiredFieldPath(GOOGLE_CHECK_NOTNULL(destination->GetDescriptor())); + } + tree.TrimMessage(GOOGLE_CHECK_NOTNULL(destination)); +} + } // namespace util } // namespace protobuf } // namespace google diff --git a/src/google/protobuf/util/field_mask_util.h b/src/google/protobuf/util/field_mask_util.h index ab1f2e94..71c68fec 100644 --- a/src/google/protobuf/util/field_mask_util.h +++ b/src/google/protobuf/util/field_mask_util.h @@ -124,10 +124,17 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil { static void MergeMessageTo(const Message& source, const FieldMask& mask, const MergeOptions& options, Message* destination); + class TrimOptions; // Removes from 'message' any field that is not represented in the given // FieldMask. If the FieldMask is empty, does nothing. static void TrimMessage(const FieldMask& mask, Message* message); + // Removes from 'message' any field that is not represented in the given + // FieldMask with customized TrimOptions. + // If the FieldMask is empty, does nothing. + static void TrimMessage(const FieldMask& mask, Message* message, + const TrimOptions& options); + private: friend class SnakeCaseCamelCaseTest; // Converts a field name from snake_case to camelCase: @@ -194,6 +201,23 @@ class LIBPROTOBUF_EXPORT FieldMaskUtil::MergeOptions { bool replace_repeated_fields_; }; +class LIBPROTOBUF_EXPORT FieldMaskUtil::TrimOptions { + public: + TrimOptions() + : keep_required_fields_(false) {} + // When trimming message fields, the default behavior is to trim required + // fields of the present message if they are not specified in the field mask. + // If you instead want to keep required fields of the present message even + // they are not speicifed in the field mask, set this flag to true. + void set_keep_required_fields(bool value) { + keep_required_fields_ = value; + } + bool keep_required_fields() const { return keep_required_fields_; } + + private: + bool keep_required_fields_; +}; + } // namespace util } // namespace protobuf diff --git a/src/google/protobuf/util/field_mask_util_test.cc b/src/google/protobuf/util/field_mask_util_test.cc index f952786f..24943ed1 100644 --- a/src/google/protobuf/util/field_mask_util_test.cc +++ b/src/google/protobuf/util/field_mask_util_test.cc @@ -114,6 +114,8 @@ TEST_F(SnakeCaseCamelCaseTest, RoundTripTest) { } using protobuf_unittest::TestAllTypes; +using protobuf_unittest::TestRequired; +using protobuf_unittest::TestRequiredMessage; using protobuf_unittest::NestedTestAllTypes; using google::protobuf::FieldMask; @@ -618,6 +620,84 @@ TEST(FieldMaskUtilTest, TrimMessage) { FieldMask empty_mask; FieldMaskUtil::TrimMessage(empty_mask, &trimmed_all_types); EXPECT_EQ(trimmed_all_types.DebugString(), all_types_msg.DebugString()); + + // Test trim required fields with keep_required_fields is set true. + FieldMaskUtil::TrimOptions options; + TestRequired required_msg_1; + required_msg_1.set_a(1234); + required_msg_1.set_b(3456); + required_msg_1.set_c(5678); + TestRequired trimmed_required_msg_1(required_msg_1); + FieldMaskUtil::FromString("dummy2", &mask); + options.set_keep_required_fields(true); + FieldMaskUtil::TrimMessage(mask, &trimmed_required_msg_1, options); + EXPECT_EQ(trimmed_required_msg_1.DebugString(), required_msg_1.DebugString()); + + // Test trim required fields with keep_required_fields is set false. + required_msg_1.clear_a(); + required_msg_1.clear_b(); + required_msg_1.clear_c(); + options.set_keep_required_fields(false); + FieldMaskUtil::TrimMessage(mask, &trimmed_required_msg_1, options); + EXPECT_EQ(trimmed_required_msg_1.DebugString(), required_msg_1.DebugString()); + + // Test trim required message with keep_required_fields is set true. + TestRequiredMessage required_msg_2; + required_msg_2.mutable_optional_message()->set_a(1234); + required_msg_2.mutable_optional_message()->set_b(3456); + required_msg_2.mutable_optional_message()->set_c(5678); + required_msg_2.mutable_required_message()->set_a(1234); + required_msg_2.mutable_required_message()->set_b(3456); + required_msg_2.mutable_required_message()->set_c(5678); + required_msg_2.mutable_required_message()->set_dummy2(7890); + TestRequired* repeated_msg = required_msg_2.add_repeated_message(); + repeated_msg->set_a(1234); + repeated_msg->set_b(3456); + repeated_msg->set_c(5678); + TestRequiredMessage trimmed_required_msg_2(required_msg_2); + FieldMaskUtil::FromString("optional_message.dummy2", &mask); + options.set_keep_required_fields(true); + required_msg_2.clear_repeated_message(); + required_msg_2.mutable_required_message()->clear_dummy2(); + FieldMaskUtil::TrimMessage(mask, &trimmed_required_msg_2, options); + EXPECT_EQ(trimmed_required_msg_2.DebugString(), + required_msg_2.DebugString()); + + FieldMaskUtil::FromString("required_message", &mask); + required_msg_2.mutable_required_message()->set_dummy2(7890); + trimmed_required_msg_2.mutable_required_message()->set_dummy2(7890); + required_msg_2.clear_optional_message(); + FieldMaskUtil::TrimMessage(mask, &trimmed_required_msg_2, options); + EXPECT_EQ(trimmed_required_msg_2.DebugString(), + required_msg_2.DebugString()); + + // Test trim required message with keep_required_fields is set false. + FieldMaskUtil::FromString("required_message.dummy2", &mask); + required_msg_2.mutable_required_message()->clear_a(); + required_msg_2.mutable_required_message()->clear_b(); + required_msg_2.mutable_required_message()->clear_c(); + options.set_keep_required_fields(false); + FieldMaskUtil::TrimMessage(mask, &trimmed_required_msg_2, options); + EXPECT_EQ(trimmed_required_msg_2.DebugString(), + required_msg_2.DebugString()); + + // Verify that trimming an empty message has no effect. In particular, fields + // mentioned in the field mask should not be created or changed. + TestAllTypes empty_msg; + FieldMaskUtil::FromString( + "optional_int32,optional_bytes,optional_nested_message.bb", &mask); + FieldMaskUtil::TrimMessage(mask, &empty_msg); + EXPECT_FALSE(empty_msg.has_optional_int32()); + EXPECT_FALSE(empty_msg.has_optional_bytes()); + EXPECT_FALSE(empty_msg.has_optional_nested_message()); + + // Verify trimming of oneof fields. This should work as expected even if + // multiple elements of the same oneof are included in the FieldMask. + TestAllTypes oneof_msg; + oneof_msg.set_oneof_uint32(11); + FieldMaskUtil::FromString("oneof_uint32,oneof_nested_message.bb", &mask); + FieldMaskUtil::TrimMessage(mask, &oneof_msg); + EXPECT_EQ(11, oneof_msg.oneof_uint32()); } diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.cc b/src/google/protobuf/util/internal/default_value_objectwriter.cc index 5763d0c6..95b3a17d 100644 --- a/src/google/protobuf/util/internal/default_value_objectwriter.cc +++ b/src/google/protobuf/util/internal/default_value_objectwriter.cc @@ -637,6 +637,7 @@ void DefaultValueObjectWriter::RenderDataPiece(StringPiece name, current_->AddChild(node.release()); } else { child->set_data(data); + child->set_is_placeholder(false); } } diff --git a/src/google/protobuf/util/internal/default_value_objectwriter.h b/src/google/protobuf/util/internal/default_value_objectwriter.h index ef2cc981..09c6d23f 100644 --- a/src/google/protobuf/util/internal/default_value_objectwriter.h +++ b/src/google/protobuf/util/internal/default_value_objectwriter.h @@ -172,7 +172,7 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { // If this node is a leaf (has data), writes the current node to the // ObjectWriter; if not, then recursively writes the children to the // ObjectWriter. - void WriteTo(ObjectWriter* ow); + virtual void WriteTo(ObjectWriter* ow); // Accessors const string& name() const { return name_; } @@ -262,6 +262,10 @@ class LIBPROTOBUF_EXPORT DefaultValueObjectWriter : public ObjectWriter { static DataPiece CreateDefaultDataPieceForField( const google::protobuf::Field& field, const TypeInfo* typeinfo); + protected: + // Returns a pointer to current Node in tree. + Node* current() { return current_; } + private: // Populates children of "node" if it is an "any" Node and its real type has // been given. diff --git a/src/google/protobuf/util/internal/protostream_objectsource.cc b/src/google/protobuf/util/internal/protostream_objectsource.cc index 025fbd40..02360a1a 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource.cc @@ -125,6 +125,7 @@ ProtoStreamObjectSource::ProtoStreamObjectSource( recursion_depth_(0), max_recursion_depth_(kDefaultMaxRecursionDepth), render_unknown_fields_(false), + render_unknown_enum_values_(true), add_trailing_zeros_for_timestamp_and_duration_(false) { GOOGLE_LOG_IF(DFATAL, stream == NULL) << "Input stream is NULL."; } @@ -142,6 +143,7 @@ ProtoStreamObjectSource::ProtoStreamObjectSource( recursion_depth_(0), max_recursion_depth_(kDefaultMaxRecursionDepth), render_unknown_fields_(false), + render_unknown_enum_values_(true), add_trailing_zeros_for_timestamp_and_duration_(false) { GOOGLE_LOG_IF(DFATAL, stream == NULL) << "Input stream is NULL."; } @@ -866,12 +868,6 @@ Status ProtoStreamObjectSource::RenderNonMessageField( break; } - // No need to lookup enum type if we need to render int. - if (use_ints_for_enums_) { - ow->RenderInt32(field_name, buffer32); - break; - } - // Get the nested enum type for this field. // TODO(skarvaje): Avoid string manipulation. Find ways to speed this // up. @@ -883,14 +879,17 @@ Status ProtoStreamObjectSource::RenderNonMessageField( const google::protobuf::EnumValue* enum_value = FindEnumValueByNumber(*en, buffer32); if (enum_value != NULL) { - if (use_lower_camel_for_enums_) + if (use_ints_for_enums_) { + ow->RenderInt32(field_name, buffer32); + } else if (use_lower_camel_for_enums_) { ow->RenderString(field_name, ToCamelCase(enum_value->name())); - else + } else { ow->RenderString(field_name, enum_value->name()); - } else { + } + } else if (render_unknown_enum_values_) { ow->RenderInt32(field_name, buffer32); } - } else { + } else if (render_unknown_enum_values_) { ow->RenderInt32(field_name, buffer32); } break; diff --git a/src/google/protobuf/util/internal/protostream_objectsource.h b/src/google/protobuf/util/internal/protostream_objectsource.h index 58d77c2c..b56efdf4 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource.h +++ b/src/google/protobuf/util/internal/protostream_objectsource.h @@ -309,6 +309,9 @@ class LIBPROTOBUF_EXPORT ProtoStreamObjectSource : public ObjectSource { // Whether to render unknown fields. bool render_unknown_fields_; + // Whether to render unknown enum values. + bool render_unknown_enum_values_; + // Whether to add trailing zeros for timestamp and duration. bool add_trailing_zeros_for_timestamp_and_duration_; diff --git a/src/google/protobuf/util/internal/protostream_objectsource_test.cc b/src/google/protobuf/util/internal/protostream_objectsource_test.cc index 06c9bb6d..36bb1ba9 100644 --- a/src/google/protobuf/util/internal/protostream_objectsource_test.cc +++ b/src/google/protobuf/util/internal/protostream_objectsource_test.cc @@ -103,7 +103,8 @@ class ProtostreamObjectSourceTest ow_(&mock_), use_lower_camel_for_enums_(false), use_ints_for_enums_(false), - add_trailing_zeros_(false) { + add_trailing_zeros_(false), + render_unknown_enum_values_(true) { helper_.ResetTypeInfo(Book::descriptor(), Proto3Message::descriptor()); } @@ -276,6 +277,10 @@ class ProtostreamObjectSourceTest void AddTrailingZeros() { add_trailing_zeros_ = true; } + void SetRenderUnknownEnumValues(bool value) { + render_unknown_enum_values_ = value; + } + testing::TypeInfoTestHelper helper_; ::testing::NiceMock<MockObjectWriter> mock_; @@ -283,6 +288,7 @@ class ProtostreamObjectSourceTest bool use_lower_camel_for_enums_; bool use_ints_for_enums_; bool add_trailing_zeros_; + bool render_unknown_enum_values_; }; INSTANTIATE_TEST_CASE_P(DifferentTypeInfoSourceTest, @@ -513,12 +519,27 @@ TEST_P(ProtostreamObjectSourceTest, UseIntsForEnumsTest) { DoTest(book, Book::descriptor()); } -TEST_P(ProtostreamObjectSourceTest, UnknownEnum) { +TEST_P(ProtostreamObjectSourceTest, + UnknownEnumAreDroppedWhenRenderUnknownEnumValuesIsUnset) { Proto3Message message; message.set_enum_value(static_cast<Proto3Message::NestedEnum>(1234)); - ow_.StartObject("") - ->RenderInt32("enumValue", 1234) - ->EndObject(); + + SetRenderUnknownEnumValues(false); + + // Unknown enum values are not output. + ow_.StartObject("")->EndObject(); + DoTest(message, Proto3Message::descriptor()); +} + +TEST_P(ProtostreamObjectSourceTest, + UnknownEnumAreOutputWhenRenderUnknownEnumValuesIsSet) { + Proto3Message message; + message.set_enum_value(static_cast<Proto3Message::NestedEnum>(1234)); + + SetRenderUnknownEnumValues(true); + + // Unknown enum values are output. + ow_.StartObject("")->RenderInt32("enumValue", 1234)->EndObject(); DoTest(message, Proto3Message::descriptor()); } diff --git a/src/google/protobuf/util/internal/protostream_objectwriter.cc b/src/google/protobuf/util/internal/protostream_objectwriter.cc index d4e15bca..97f96819 100644 --- a/src/google/protobuf/util/internal/protostream_objectwriter.cc +++ b/src/google/protobuf/util/internal/protostream_objectwriter.cc @@ -962,7 +962,7 @@ Status ProtoStreamObjectWriter::RenderFieldMask(ProtoStreamObjectWriter* ow, // conversions as much as possible. Because ToSnakeCase sometimes returns the // wrong value. google::protobuf::scoped_ptr<ResultCallback1<util::Status, StringPiece> > callback( - NewPermanentCallback(&RenderOneFieldPath, ow)); + ::google::protobuf::NewPermanentCallback(&RenderOneFieldPath, ow)); return DecodeCompactFieldMaskPaths(data.str(), callback.get()); } diff --git a/src/google/protobuf/util/internal/utility.cc b/src/google/protobuf/util/internal/utility.cc index 8cf42e49..11780ee8 100644 --- a/src/google/protobuf/util/internal/utility.cc +++ b/src/google/protobuf/util/internal/utility.cc @@ -124,7 +124,10 @@ const StringPiece GetTypeWithoutUrl(StringPiece type_url) { return type_url.substr(kTypeUrlSize + 1); } else { size_t idx = type_url.rfind('/'); - return type_url.substr(idx + 1); + if (idx != type_url.npos) { + type_url.remove_prefix(idx + 1); + } + return type_url; } } diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc index 830850be..d62038ad 100644 --- a/src/google/protobuf/util/message_differencer.cc +++ b/src/google/protobuf/util/message_differencer.cc @@ -53,6 +53,7 @@ #include <google/protobuf/io/printer.h> #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/io/zero_copy_stream_impl.h> +#include <google/protobuf/descriptor.pb.h> #include <google/protobuf/dynamic_message.h> #include <google/protobuf/text_format.h> #include <google/protobuf/util/field_comparator.h> @@ -150,6 +151,32 @@ class MessageDifferencer::MultipleFieldsMapKeyComparator GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(MultipleFieldsMapKeyComparator); }; +MessageDifferencer::MapEntryKeyComparator::MapEntryKeyComparator( + MessageDifferencer* message_differencer) + : message_differencer_(message_differencer) {} + +bool MessageDifferencer::MapEntryKeyComparator::IsMatch( + const Message& message1, const Message& message2, + const std::vector<SpecificField>& parent_fields) const { + // Map entry has its key in the field with tag 1. See the comment for + // map_entry in MessageOptions. + const FieldDescriptor* key = message1.GetDescriptor()->FindFieldByNumber(1); + // If key is not present in message1 and we're doing partial comparison or if + // map key is explicitly ignored treat the field as set instead, + const bool treat_as_set = + (message_differencer_->scope() == PARTIAL && + !message1.GetReflection()->HasField(message1, key)) || + message_differencer_->IsIgnored(message1, message2, key, parent_fields); + + std::vector<SpecificField> current_parent_fields(parent_fields); + if (treat_as_set) { + return message_differencer_->Compare(message1, message2, + ¤t_parent_fields); + } + return message_differencer_->CompareFieldValueUsingParentFields( + message1, message2, key, -1, -1, ¤t_parent_fields); +} + bool MessageDifferencer::Equals(const Message& message1, const Message& message2) { MessageDifferencer differencer; @@ -191,8 +218,10 @@ MessageDifferencer::MessageDifferencer() message_field_comparison_(EQUAL), scope_(FULL), repeated_field_comparison_(AS_LIST), + map_entry_key_comparator_(this), report_matches_(false), - output_string_(NULL) { } + report_moves_(true), + output_string_(NULL) {} MessageDifferencer::~MessageDifferencer() { for (int i = 0; i < owned_key_comparators_.size(); ++i) { @@ -484,8 +513,22 @@ bool MessageDifferencer::Compare( std::vector<const FieldDescriptor*> message2_fields; message2_fields.reserve(1 + message2.GetDescriptor()->field_count()); - reflection1->ListFields(message1, &message1_fields); - reflection2->ListFields(message2, &message2_fields); + if (descriptor1->options().map_entry()) { + if (scope_ == PARTIAL) { + reflection1->ListFields(message1, &message1_fields); + } else { + // Map entry fields are always considered present. + for (int i = 0; i < descriptor1->field_count(); i++) { + message1_fields.push_back(descriptor1->field(i)); + } + } + for (int i = 0; i < descriptor1->field_count(); i++) { + message2_fields.push_back(descriptor1->field(i)); + } + } else { + reflection1->ListFields(message1, &message1_fields); + reflection2->ListFields(message2, &message2_fields); + } // Add sentinel values to deal with the // case where the number of the fields in @@ -783,6 +826,8 @@ bool MessageDifferencer::IsMatch( reflection2->GetRepeatedMessage(*message2, repeated_field, index2); SpecificField specific_field; specific_field.field = repeated_field; + specific_field.index = index1; + specific_field.new_index = index2; current_parent_fields.push_back(specific_field); match = key_comparator->IsMatch(m1, m2, current_parent_fields); } @@ -854,7 +899,7 @@ bool MessageDifferencer::CompareRepeatedField( fieldDifferent = true; } else if (reporter_ != NULL && specific_field.index != specific_field.new_index && - !specific_field.field->is_map()) { + !specific_field.field->is_map() && report_moves_) { parent_fields->push_back(specific_field); reporter_->ReportMoved(message1, message2, *parent_fields); parent_fields->pop_back(); @@ -945,6 +990,8 @@ bool MessageDifferencer::CompareFieldValueUsingParentFields( bool MessageDifferencer::CheckPathChanged( const std::vector<SpecificField>& field_path) { for (int i = 0; i < field_path.size(); ++i) { + // Don't check indexes for map entries -- maps are unordered. + if (field_path[i].field != NULL && field_path[i].field->is_map()) continue; if (field_path[i].index != field_path[i].new_index) return true; } return false; @@ -952,7 +999,6 @@ bool MessageDifferencer::CheckPathChanged( bool MessageDifferencer::IsTreatedAsSet(const FieldDescriptor* field) { if (!field->is_repeated()) return false; - if (field->is_map()) return true; if (repeated_field_comparison_ == AS_SET) return list_fields_.find(field) == list_fields_.end(); return (set_fields_.find(field) != set_fields_.end()); @@ -993,12 +1039,18 @@ bool MessageDifferencer::IsUnknownFieldIgnored( return false; } -const MessageDifferencer::MapKeyComparator* MessageDifferencer - ::GetMapKeyComparator(const FieldDescriptor* field) { +const MessageDifferencer::MapKeyComparator* +MessageDifferencer ::GetMapKeyComparator(const FieldDescriptor* field) const { if (!field->is_repeated()) return NULL; - if (map_field_key_comparator_.find(field) != - map_field_key_comparator_.end()) { - return map_field_key_comparator_[field]; + FieldKeyComparatorMap::const_iterator it = + map_field_key_comparator_.find(field); + if (it != map_field_key_comparator_.end()) { + return it->second; + } + if (field->is_map()) { + // field cannot already be treated as list or set since TreatAsList() and + // TreatAsSet() call GetMapKeyComparator() and fail if it returns non-NULL. + return &map_entry_key_comparator_; } return NULL; } @@ -1400,7 +1452,7 @@ bool MessageDifferencer::MatchRepeatedFieldIndices( // algorithm will fail to find a maximum matching. // Here we use the argumenting path algorithm. MaximumMatcher::NodeMatchCallback* callback = - NewPermanentCallback( + ::google::protobuf::NewPermanentCallback( this, &MessageDifferencer::IsMatch, repeated_field, key_comparator, &message1, &message2, parent_fields); @@ -1524,6 +1576,12 @@ void MessageDifferencer::StreamReporter::PrintPath( } } +void MessageDifferencer::StreamReporter::PrintPath( + const std::vector<SpecificField>& field_path, bool left_side, + const Message& message) { + PrintPath(field_path, left_side); +} + void MessageDifferencer:: StreamReporter::PrintValue(const Message& message, const std::vector<SpecificField>& field_path, @@ -1601,7 +1659,7 @@ void MessageDifferencer::StreamReporter::ReportAdded( const Message& message2, const std::vector<SpecificField>& field_path) { printer_->Print("added: "); - PrintPath(field_path, false); + PrintPath(field_path, false, message2); printer_->Print(": "); PrintValue(message2, field_path, false); printer_->Print("\n"); // Print for newlines. @@ -1612,7 +1670,7 @@ void MessageDifferencer::StreamReporter::ReportDeleted( const Message& message2, const std::vector<SpecificField>& field_path) { printer_->Print("deleted: "); - PrintPath(field_path, true); + PrintPath(field_path, true, message1); printer_->Print(": "); PrintValue(message1, field_path, true); printer_->Print("\n"); // Print for newlines @@ -1636,10 +1694,10 @@ void MessageDifferencer::StreamReporter::ReportModified( } printer_->Print("modified: "); - PrintPath(field_path, true); + PrintPath(field_path, true, message1); if (CheckPathChanged(field_path)) { printer_->Print(" -> "); - PrintPath(field_path, false); + PrintPath(field_path, false, message2); } printer_->Print(": "); PrintValue(message1, field_path, true); @@ -1653,9 +1711,9 @@ void MessageDifferencer::StreamReporter::ReportMoved( const Message& message2, const std::vector<SpecificField>& field_path) { printer_->Print("moved: "); - PrintPath(field_path, true); + PrintPath(field_path, true, message1); printer_->Print(" -> "); - PrintPath(field_path, false); + PrintPath(field_path, false, message2); printer_->Print(" : "); PrintValue(message1, field_path, true); printer_->Print("\n"); // Print for newlines. @@ -1666,10 +1724,10 @@ void MessageDifferencer::StreamReporter::ReportMatched( const Message& message2, const std::vector<SpecificField>& field_path) { printer_->Print("matched: "); - PrintPath(field_path, true); + PrintPath(field_path, true, message1); if (CheckPathChanged(field_path)) { printer_->Print(" -> "); - PrintPath(field_path, false); + PrintPath(field_path, false, message2); } printer_->Print(" : "); PrintValue(message1, field_path, true); @@ -1681,10 +1739,10 @@ void MessageDifferencer::StreamReporter::ReportIgnored( const Message& message2, const std::vector<SpecificField>& field_path) { printer_->Print("ignored: "); - PrintPath(field_path, true); + PrintPath(field_path, true, message1); if (CheckPathChanged(field_path)) { printer_->Print(" -> "); - PrintPath(field_path, false); + PrintPath(field_path, false, message2); } printer_->Print("\n"); // Print for newlines. } @@ -1693,10 +1751,10 @@ void MessageDifferencer::StreamReporter::ReportUnknownFieldIgnored( const Message& message1, const Message& message2, const std::vector<SpecificField>& field_path) { printer_->Print("ignored: "); - PrintPath(field_path, true); + PrintPath(field_path, true, message1); if (CheckPathChanged(field_path)) { printer_->Print(" -> "); - PrintPath(field_path, false); + PrintPath(field_path, false, message2); } printer_->Print("\n"); // Print for newlines. } diff --git a/src/google/protobuf/util/message_differencer.h b/src/google/protobuf/util/message_differencer.h index d99223cb..fdbf04e4 100644 --- a/src/google/protobuf/util/message_differencer.h +++ b/src/google/protobuf/util/message_differencer.h @@ -518,6 +518,13 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { report_matches_ = report_matches; } + // Tells the differencer whether or not to report moves (in a set or map + // repeated field). This method must be called before Compare. The default for + // a new differencer is true. + void set_report_moves(bool report_moves) { + report_moves_ = report_moves; + } + // Sets the scope of the comparison (as defined in the Scope enumeration // above) that is used by this differencer when determining which fields to // compare between the messages. @@ -620,6 +627,11 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { const std::vector<SpecificField>& field_path); protected: + // Prints the specified path of fields to the buffer. message is used to + // print map keys. + virtual void PrintPath(const std::vector<SpecificField>& field_path, + bool left_side, const Message& message); + // Prints the specified path of fields to the buffer. virtual void PrintPath(const std::vector<SpecificField>& field_path, bool left_side); @@ -653,6 +665,18 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { // relies on some private methods of MessageDifferencer. That's why this // class is declared as a nested class of MessageDifferencer. class MultipleFieldsMapKeyComparator; + + // A MapKeyComparator for use with map_entries. + class LIBPROTOBUF_EXPORT MapEntryKeyComparator : public MapKeyComparator { + public: + explicit MapEntryKeyComparator(MessageDifferencer* message_differencer); + virtual bool IsMatch(const Message& message1, const Message& message2, + const std::vector<SpecificField>& parent_fields) const; + + private: + MessageDifferencer* message_differencer_; + }; + // Returns true if field1's number() is less than field2's. static bool FieldBefore(const FieldDescriptor* field1, const FieldDescriptor* field2); @@ -765,9 +789,10 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { const SpecificField& field, const std::vector<SpecificField>& parent_fields); - // Returns MapKeyComparator* when this field has been configured to - // be treated as a map. If not, returns NULL. - const MapKeyComparator* GetMapKeyComparator(const FieldDescriptor* field); + // Returns MapKeyComparator* when this field has been configured to be treated + // as a map or its is_map() return true. If not, returns NULL. + const MapKeyComparator* GetMapKeyComparator( + const FieldDescriptor* field) const; // Attempts to match indices of a repeated field, so that the contained values // match. Clears output vectors and sets their values to indices of paired @@ -817,11 +842,13 @@ class LIBPROTOBUF_EXPORT MessageDifferencer { // MapKeyComparator is created for comparison purpose. std::vector<MapKeyComparator*> owned_key_comparators_; FieldKeyComparatorMap map_field_key_comparator_; + MapEntryKeyComparator map_entry_key_comparator_; std::vector<IgnoreCriteria*> ignore_criteria_; FieldSet ignored_fields_; bool report_matches_; + bool report_moves_; string* output_string_; diff --git a/src/google/protobuf/util/message_differencer_unittest.cc b/src/google/protobuf/util/message_differencer_unittest.cc index 850b3977..75cffd9f 100755 --- a/src/google/protobuf/util/message_differencer_unittest.cc +++ b/src/google/protobuf/util/message_differencer_unittest.cc @@ -1558,6 +1558,43 @@ TEST(MessageDifferencerTest, RepeatedFieldMapTest_CustomMapKeyComparator) { EXPECT_EQ("ignored: item[0].ra\n", output); } +// Compares fields by their index offset by one, so index 0 matches with 1, etc. +class OffsetByOneMapKeyComparator + : public util::MessageDifferencer::MapKeyComparator { + public: + typedef util::MessageDifferencer::SpecificField SpecificField; + virtual bool IsMatch(const Message& message1, const Message& message2, + const std::vector<SpecificField>& parent_fields) const { + return parent_fields.back().index + 1 == parent_fields.back().new_index; + } +}; + +TEST(MessageDifferencerTest, RepeatedFieldMapTest_CustomIndexMapKeyComparator) { + protobuf_unittest::TestDiffMessage msg1; + protobuf_unittest::TestDiffMessage msg2; + // Treat "item" as Map, using custom key comparator to determine if two + // elements have the same key. + protobuf_unittest::TestDiffMessage::Item* item = msg1.add_item(); + item->set_b("one"); + item = msg2.add_item(); + item->set_b("zero"); + item = msg2.add_item(); + item->set_b("one"); + util::MessageDifferencer differencer; + OffsetByOneMapKeyComparator key_comparator; + differencer.TreatAsMapUsingKeyComparator(GetFieldDescriptor(msg1, "item"), + &key_comparator); + string output; + differencer.ReportDifferencesToString(&output); + // With the offset by one comparator msg1.item[0] should be compared to + // msg2.item[1] and thus be moved, msg2.item[0] should be marked as added. + EXPECT_FALSE(differencer.Compare(msg1, msg2)); + EXPECT_EQ( + "moved: item[0] -> item[1] : { b: \"one\" }\n" + "added: item[0]: { b: \"zero\" }\n", + output); +} + TEST(MessageDifferencerTest, RepeatedFieldSetTest_Subset) { protobuf_unittest::TestDiffMessage msg1; protobuf_unittest::TestDiffMessage msg2; @@ -2806,21 +2843,130 @@ TEST_F(ComparisonTest, EquivalentIgnoresUnknown) { } TEST_F(ComparisonTest, MapTest) { - repeated_field_as_set(); + Map<string, string>& map1 = *map_proto1_.mutable_map_string_string(); + map1["key1"] = "1"; + map1["key2"] = "2"; + map1["key3"] = "3"; + Map<string, string>& map2 = *map_proto2_.mutable_map_string_string(); + map2["key3"] = "0"; + map2["key2"] = "2"; + map2["key1"] = "1"; + + EXPECT_EQ("modified: map_string_string.value: \"3\" -> \"0\"\n", + Run(map_proto1_, map_proto2_)); +} +TEST_F(ComparisonTest, MapIgnoreKeyTest) { Map<string, string>& map1 = *map_proto1_.mutable_map_string_string(); - map1["1"] = "1"; - map1["2"] = "2"; - map1["3"] = "3"; + map1["key1"] = "1"; + map1["key2"] = "2"; + map1["key3"] = "3"; Map<string, string>& map2 = *map_proto2_.mutable_map_string_string(); - map2["3"] = "0"; - map2["2"] = "2"; - map2["1"] = "1"; + map2["key4"] = "2"; + map2["key5"] = "3"; + map2["key6"] = "1"; - EXPECT_EQ( - "added: map_string_string: { key: \"3\" value: \"0\" }\n" - "deleted: map_string_string: { key: \"3\" value: \"3\" }\n", - Run(map_proto1_, map_proto2_)); + util::MessageDifferencer differencer; + differencer.IgnoreField( + GetFieldDescriptor(map_proto1_, "map_string_string.key")); + EXPECT_TRUE(differencer.Compare(map_proto1_, map_proto2_)); +} + +TEST_F(ComparisonTest, MapRoundTripSyncTest) { + google::protobuf::TextFormat::Parser parser; + unittest::TestMap map_reflection1; + + // By setting via reflection, data exists in repeated field. + ASSERT_TRUE(parser.ParseFromString( + "map_int32_foreign_message { key: 1 }", &map_reflection1)); + + // During copy, data is synced from repeated field to map. + unittest::TestMap map_reflection2 = map_reflection1; + + // During comparison, data is synced from map to repeated field. + EXPECT_TRUE( + util::MessageDifferencer::Equals(map_reflection1, map_reflection2)); +} + +TEST_F(ComparisonTest, MapEntryPartialTest) { + google::protobuf::TextFormat::Parser parser; + unittest::TestMap map1; + unittest::TestMap map2; + + string output; + util::MessageDifferencer differencer; + differencer.set_scope(util::MessageDifferencer::PARTIAL); + differencer.ReportDifferencesToString(&output); + + ASSERT_TRUE(parser.ParseFromString( + "map_int32_foreign_message { key: 1 value { c: 1 } }", &map1)); + ASSERT_TRUE(parser.ParseFromString( + "map_int32_foreign_message { key: 1 value { c: 2 }}", &map2)); + EXPECT_FALSE(differencer.Compare(map1, map2)); + EXPECT_EQ("modified: map_int32_foreign_message.value.c: 1 -> 2\n", output); + + ASSERT_TRUE( + parser.ParseFromString("map_int32_foreign_message { key: 1 }", &map1)); + EXPECT_TRUE(differencer.Compare(map1, map2)); +} + +TEST_F(ComparisonTest, MapEntryPartialEmptyKeyTest) { + google::protobuf::TextFormat::Parser parser; + unittest::TestMap map1; + unittest::TestMap map2; + ASSERT_TRUE(parser.ParseFromString("map_int32_foreign_message {}", &map1)); + ASSERT_TRUE( + parser.ParseFromString("map_int32_foreign_message { key: 1 }", &map2)); + + util::MessageDifferencer differencer; + differencer.set_scope(util::MessageDifferencer::PARTIAL); + EXPECT_TRUE(differencer.Compare(map1, map2)); +} + +// Considers strings keys as equal if they have equal lengths. +class LengthMapKeyComparator + : public util::MessageDifferencer::MapKeyComparator { + public: + typedef util::MessageDifferencer::SpecificField SpecificField; + virtual bool IsMatch(const Message& message1, const Message& message2, + const std::vector<SpecificField>& parent_fields) const { + const Reflection* reflection1 = message1.GetReflection(); + const Reflection* reflection2 = message2.GetReflection(); + const FieldDescriptor* key_field = + message1.GetDescriptor()->FindFieldByName("key"); + return reflection1->GetString(message1, key_field).size() == + reflection2->GetString(message2, key_field).size(); + } +}; + +TEST_F(ComparisonTest, MapEntryCustomMapKeyComparator) { + google::protobuf::TextFormat::Parser parser; + protobuf_unittest::TestMap msg1; + protobuf_unittest::TestMap msg2; + + ASSERT_TRUE(parser.ParseFromString( + "map_string_foreign_message { key: 'key1' value { c: 1 }}", &msg1)); + ASSERT_TRUE(parser.ParseFromString( + "map_string_foreign_message { key: 'key2' value { c: 1 }}", &msg2)); + + util::MessageDifferencer differencer; + LengthMapKeyComparator key_comparator; + differencer.TreatAsMapUsingKeyComparator( + GetFieldDescriptor(msg1, "map_string_foreign_message"), &key_comparator); + string output; + differencer.ReportDifferencesToString(&output); + // Though the above two messages have different keys for their map entries, + // they are considered the same by key_comparator because their lengths are + // equal. However, in value comparison, all fields of the message are taken + // into consideration, so they are reported as different. + EXPECT_FALSE(differencer.Compare(msg1, msg2)); + EXPECT_EQ("modified: map_string_foreign_message.key: \"key1\" -> \"key2\"\n", + output); + differencer.IgnoreField( + GetFieldDescriptor(msg1, "map_string_foreign_message.key")); + output.clear(); + EXPECT_TRUE(differencer.Compare(msg1, msg2)); + EXPECT_EQ("ignored: map_string_foreign_message.key\n", output); } class MatchingTest : public testing::Test { diff --git a/src/google/protobuf/wire_format.h b/src/google/protobuf/wire_format.h index 5e9aca52..01ee1337 100644 --- a/src/google/protobuf/wire_format.h +++ b/src/google/protobuf/wire_format.h @@ -46,11 +46,6 @@ #include <google/protobuf/message.h> #include <google/protobuf/wire_format_lite.h> -// Do UTF-8 validation on string type in Debug build only -#ifndef NDEBUG -#define GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED -#endif - namespace google { namespace protobuf { namespace io { diff --git a/src/google/protobuf/wire_format_lite.cc b/src/google/protobuf/wire_format_lite.cc index 7987f7c4..359353c3 100644 --- a/src/google/protobuf/wire_format_lite.cc +++ b/src/google/protobuf/wire_format_lite.cc @@ -47,8 +47,8 @@ #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/io/zero_copy_stream_impl_lite.h> -namespace google { +namespace google { namespace protobuf { namespace internal { diff --git a/src/google/protobuf/wire_format_lite.h b/src/google/protobuf/wire_format_lite.h index 18b38eae..346d5b2a 100644 --- a/src/google/protobuf/wire_format_lite.h +++ b/src/google/protobuf/wire_format_lite.h @@ -46,6 +46,11 @@ #include <google/protobuf/message_lite.h> #include <google/protobuf/io/coded_stream.h> // for CodedOutputStream::Varint32Size +// Do UTF-8 validation on string type in Debug build only +#ifndef NDEBUG +#define GOOGLE_PROTOBUF_UTF8_VALIDATION_ENABLED +#endif + // Avoid conflict with iOS where <ConditionalMacros.h> #defines TYPE_BOOL. // // If some one needs the macro TYPE_BOOL in a file that includes this header, it's diff --git a/src/google/protobuf/wrappers.pb.cc b/src/google/protobuf/wrappers.pb.cc index 12c04fd5..67d04409 100644 --- a/src/google/protobuf/wrappers.pb.cc +++ b/src/google/protobuf/wrappers.pb.cc @@ -48,16 +48,16 @@ namespace { } // namespace PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTableField - const TableStruct::entries[] = { + const TableStruct::entries[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { {0, 0, 0, ::google::protobuf::internal::kInvalidMask, 0, 0}, }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::AuxillaryParseTableField - const TableStruct::aux[] = { + const TableStruct::aux[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ::google::protobuf::internal::AuxillaryParseTableField(), }; PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const - TableStruct::schema[] = { + TableStruct::schema[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, { NULL, NULL, 0, -1, -1, false }, @@ -69,7 +69,7 @@ PROTOBUF_CONSTEXPR_VAR ::google::protobuf::internal::ParseTable const { NULL, NULL, 0, -1, -1, false }, }; -const ::google::protobuf::uint32 TableStruct::offsets[] = { +const ::google::protobuf::uint32 TableStruct::offsets[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { ~0u, // no _has_bits_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(DoubleValue, _internal_metadata_), ~0u, // no _extensions_ @@ -125,8 +125,7 @@ const ::google::protobuf::uint32 TableStruct::offsets[] = { ~0u, // no _weak_field_map_ GOOGLE_PROTOBUF_GENERATED_MESSAGE_FIELD_OFFSET(BytesValue, value_), }; - -static const ::google::protobuf::internal::MigrationSchema schemas[] = { +static const ::google::protobuf::internal::MigrationSchema schemas[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { { 0, -1, sizeof(DoubleValue)}, { 6, -1, sizeof(FloatValue)}, { 12, -1, sizeof(Int64Value)}, @@ -172,28 +171,6 @@ void protobuf_RegisterTypes(const ::std::string&) { } } // namespace - -void TableStruct::Shutdown() { - _DoubleValue_default_instance_.Shutdown(); - delete file_level_metadata[0].reflection; - _FloatValue_default_instance_.Shutdown(); - delete file_level_metadata[1].reflection; - _Int64Value_default_instance_.Shutdown(); - delete file_level_metadata[2].reflection; - _UInt64Value_default_instance_.Shutdown(); - delete file_level_metadata[3].reflection; - _Int32Value_default_instance_.Shutdown(); - delete file_level_metadata[4].reflection; - _UInt32Value_default_instance_.Shutdown(); - delete file_level_metadata[5].reflection; - _BoolValue_default_instance_.Shutdown(); - delete file_level_metadata[6].reflection; - _StringValue_default_instance_.Shutdown(); - delete file_level_metadata[7].reflection; - _BytesValue_default_instance_.Shutdown(); - delete file_level_metadata[8].reflection; -} - void TableStruct::InitDefaultsImpl() { GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -215,7 +192,7 @@ void InitDefaults() { } void AddDescriptorsImpl() { InitDefaults(); - static const char descriptor[] = { + static const char descriptor[] GOOGLE_ATTRIBUTE_SECTION_VARIABLE(protodesc_cold) = { "\n\036google/protobuf/wrappers.proto\022\017google" ".protobuf\"\034\n\013DoubleValue\022\r\n\005value\030\001 \001(\001\"" "\033\n\nFloatValue\022\r\n\005value\030\001 \001(\002\"\033\n\nInt64Val" @@ -233,14 +210,13 @@ void AddDescriptorsImpl() { descriptor, 447); ::google::protobuf::MessageFactory::InternalRegisterGeneratedFile( "google/protobuf/wrappers.proto", &protobuf_RegisterTypes); - ::google::protobuf::internal::OnShutdown(&TableStruct::Shutdown); } void AddDescriptors() { static GOOGLE_PROTOBUF_DECLARE_ONCE(once); ::google::protobuf::GoogleOnceInit(&once, &AddDescriptorsImpl); } -// Force AddDescriptors() to be called at static initialization time. +// Force AddDescriptors() to be called at dynamic initialization time. struct StaticDescriptorInitializer { StaticDescriptorInitializer() { AddDescriptors(); @@ -267,9 +243,7 @@ DoubleValue::DoubleValue() DoubleValue::DoubleValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.DoubleValue) @@ -295,6 +269,7 @@ DoubleValue::~DoubleValue() { void DoubleValue::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -328,7 +303,12 @@ DoubleValue* DoubleValue::New(::google::protobuf::Arena* arena) const { void DoubleValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.DoubleValue) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + value_ = 0; + _internal_metadata_.Clear(); } bool DoubleValue::MergePartialFromCodedStream( @@ -344,7 +324,7 @@ bool DoubleValue::MergePartialFromCodedStream( // double value = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(9u)) { + static_cast< ::google::protobuf::uint8>(9u /* 9 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< double, ::google::protobuf::internal::WireFormatLite::TYPE_DOUBLE>( @@ -357,12 +337,11 @@ bool DoubleValue::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -387,6 +366,10 @@ void DoubleValue::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WriteDouble(1, this->value(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.DoubleValue) } @@ -401,6 +384,10 @@ void DoubleValue::SerializeWithCachedSizes( target = ::google::protobuf::internal::WireFormatLite::WriteDoubleToArray(1, this->value(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.DoubleValue) return target; } @@ -409,6 +396,11 @@ size_t DoubleValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.DoubleValue) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // double value = 1; if (this->value() != 0) { total_size += 1 + 8; @@ -486,8 +478,10 @@ void DoubleValue::UnsafeArenaSwap(DoubleValue* other) { InternalSwap(other); } void DoubleValue::InternalSwap(DoubleValue* other) { - std::swap(value_, other->value_); - std::swap(_cached_size_, other->_cached_size_); + using std::swap; + swap(value_, other->value_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata DoubleValue::GetMetadata() const { @@ -531,9 +525,7 @@ FloatValue::FloatValue() FloatValue::FloatValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.FloatValue) @@ -559,6 +551,7 @@ FloatValue::~FloatValue() { void FloatValue::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -592,7 +585,12 @@ FloatValue* FloatValue::New(::google::protobuf::Arena* arena) const { void FloatValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.FloatValue) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + value_ = 0; + _internal_metadata_.Clear(); } bool FloatValue::MergePartialFromCodedStream( @@ -608,7 +606,7 @@ bool FloatValue::MergePartialFromCodedStream( // float value = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(13u)) { + static_cast< ::google::protobuf::uint8>(13u /* 13 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< float, ::google::protobuf::internal::WireFormatLite::TYPE_FLOAT>( @@ -621,12 +619,11 @@ bool FloatValue::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -651,6 +648,10 @@ void FloatValue::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WriteFloat(1, this->value(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.FloatValue) } @@ -665,6 +666,10 @@ void FloatValue::SerializeWithCachedSizes( target = ::google::protobuf::internal::WireFormatLite::WriteFloatToArray(1, this->value(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.FloatValue) return target; } @@ -673,6 +678,11 @@ size_t FloatValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.FloatValue) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // float value = 1; if (this->value() != 0) { total_size += 1 + 4; @@ -750,8 +760,10 @@ void FloatValue::UnsafeArenaSwap(FloatValue* other) { InternalSwap(other); } void FloatValue::InternalSwap(FloatValue* other) { - std::swap(value_, other->value_); - std::swap(_cached_size_, other->_cached_size_); + using std::swap; + swap(value_, other->value_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata FloatValue::GetMetadata() const { @@ -795,9 +807,7 @@ Int64Value::Int64Value() Int64Value::Int64Value(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Int64Value) @@ -823,6 +833,7 @@ Int64Value::~Int64Value() { void Int64Value::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -856,7 +867,12 @@ Int64Value* Int64Value::New(::google::protobuf::Arena* arena) const { void Int64Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Int64Value) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + value_ = GOOGLE_LONGLONG(0); + _internal_metadata_.Clear(); } bool Int64Value::MergePartialFromCodedStream( @@ -872,7 +888,7 @@ bool Int64Value::MergePartialFromCodedStream( // int64 value = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int64, ::google::protobuf::internal::WireFormatLite::TYPE_INT64>( @@ -885,12 +901,11 @@ bool Int64Value::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -915,6 +930,10 @@ void Int64Value::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WriteInt64(1, this->value(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Int64Value) } @@ -929,6 +948,10 @@ void Int64Value::SerializeWithCachedSizes( target = ::google::protobuf::internal::WireFormatLite::WriteInt64ToArray(1, this->value(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Int64Value) return target; } @@ -937,6 +960,11 @@ size_t Int64Value::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Int64Value) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // int64 value = 1; if (this->value() != 0) { total_size += 1 + @@ -1016,8 +1044,10 @@ void Int64Value::UnsafeArenaSwap(Int64Value* other) { InternalSwap(other); } void Int64Value::InternalSwap(Int64Value* other) { - std::swap(value_, other->value_); - std::swap(_cached_size_, other->_cached_size_); + using std::swap; + swap(value_, other->value_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Int64Value::GetMetadata() const { @@ -1061,9 +1091,7 @@ UInt64Value::UInt64Value() UInt64Value::UInt64Value(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.UInt64Value) @@ -1089,6 +1117,7 @@ UInt64Value::~UInt64Value() { void UInt64Value::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -1122,7 +1151,12 @@ UInt64Value* UInt64Value::New(::google::protobuf::Arena* arena) const { void UInt64Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.UInt64Value) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + value_ = GOOGLE_ULONGLONG(0); + _internal_metadata_.Clear(); } bool UInt64Value::MergePartialFromCodedStream( @@ -1138,7 +1172,7 @@ bool UInt64Value::MergePartialFromCodedStream( // uint64 value = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::uint64, ::google::protobuf::internal::WireFormatLite::TYPE_UINT64>( @@ -1151,12 +1185,11 @@ bool UInt64Value::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -1181,6 +1214,10 @@ void UInt64Value::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WriteUInt64(1, this->value(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.UInt64Value) } @@ -1195,6 +1232,10 @@ void UInt64Value::SerializeWithCachedSizes( target = ::google::protobuf::internal::WireFormatLite::WriteUInt64ToArray(1, this->value(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.UInt64Value) return target; } @@ -1203,6 +1244,11 @@ size_t UInt64Value::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.UInt64Value) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // uint64 value = 1; if (this->value() != 0) { total_size += 1 + @@ -1282,8 +1328,10 @@ void UInt64Value::UnsafeArenaSwap(UInt64Value* other) { InternalSwap(other); } void UInt64Value::InternalSwap(UInt64Value* other) { - std::swap(value_, other->value_); - std::swap(_cached_size_, other->_cached_size_); + using std::swap; + swap(value_, other->value_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata UInt64Value::GetMetadata() const { @@ -1327,9 +1375,7 @@ Int32Value::Int32Value() Int32Value::Int32Value(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.Int32Value) @@ -1355,6 +1401,7 @@ Int32Value::~Int32Value() { void Int32Value::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -1388,7 +1435,12 @@ Int32Value* Int32Value::New(::google::protobuf::Arena* arena) const { void Int32Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.Int32Value) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + value_ = 0; + _internal_metadata_.Clear(); } bool Int32Value::MergePartialFromCodedStream( @@ -1404,7 +1456,7 @@ bool Int32Value::MergePartialFromCodedStream( // int32 value = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::int32, ::google::protobuf::internal::WireFormatLite::TYPE_INT32>( @@ -1417,12 +1469,11 @@ bool Int32Value::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -1447,6 +1498,10 @@ void Int32Value::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WriteInt32(1, this->value(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.Int32Value) } @@ -1461,6 +1516,10 @@ void Int32Value::SerializeWithCachedSizes( target = ::google::protobuf::internal::WireFormatLite::WriteInt32ToArray(1, this->value(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.Int32Value) return target; } @@ -1469,6 +1528,11 @@ size_t Int32Value::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.Int32Value) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // int32 value = 1; if (this->value() != 0) { total_size += 1 + @@ -1548,8 +1612,10 @@ void Int32Value::UnsafeArenaSwap(Int32Value* other) { InternalSwap(other); } void Int32Value::InternalSwap(Int32Value* other) { - std::swap(value_, other->value_); - std::swap(_cached_size_, other->_cached_size_); + using std::swap; + swap(value_, other->value_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata Int32Value::GetMetadata() const { @@ -1593,9 +1659,7 @@ UInt32Value::UInt32Value() UInt32Value::UInt32Value(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.UInt32Value) @@ -1621,6 +1685,7 @@ UInt32Value::~UInt32Value() { void UInt32Value::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -1654,7 +1719,12 @@ UInt32Value* UInt32Value::New(::google::protobuf::Arena* arena) const { void UInt32Value::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.UInt32Value) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + value_ = 0u; + _internal_metadata_.Clear(); } bool UInt32Value::MergePartialFromCodedStream( @@ -1670,7 +1740,7 @@ bool UInt32Value::MergePartialFromCodedStream( // uint32 value = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< ::google::protobuf::uint32, ::google::protobuf::internal::WireFormatLite::TYPE_UINT32>( @@ -1683,12 +1753,11 @@ bool UInt32Value::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -1713,6 +1782,10 @@ void UInt32Value::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WriteUInt32(1, this->value(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.UInt32Value) } @@ -1727,6 +1800,10 @@ void UInt32Value::SerializeWithCachedSizes( target = ::google::protobuf::internal::WireFormatLite::WriteUInt32ToArray(1, this->value(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.UInt32Value) return target; } @@ -1735,6 +1812,11 @@ size_t UInt32Value::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.UInt32Value) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // uint32 value = 1; if (this->value() != 0) { total_size += 1 + @@ -1814,8 +1896,10 @@ void UInt32Value::UnsafeArenaSwap(UInt32Value* other) { InternalSwap(other); } void UInt32Value::InternalSwap(UInt32Value* other) { - std::swap(value_, other->value_); - std::swap(_cached_size_, other->_cached_size_); + using std::swap; + swap(value_, other->value_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata UInt32Value::GetMetadata() const { @@ -1859,9 +1943,7 @@ BoolValue::BoolValue() BoolValue::BoolValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.BoolValue) @@ -1887,6 +1969,7 @@ BoolValue::~BoolValue() { void BoolValue::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -1920,7 +2003,12 @@ BoolValue* BoolValue::New(::google::protobuf::Arena* arena) const { void BoolValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.BoolValue) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + value_ = false; + _internal_metadata_.Clear(); } bool BoolValue::MergePartialFromCodedStream( @@ -1936,7 +2024,7 @@ bool BoolValue::MergePartialFromCodedStream( // bool value = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(8u)) { + static_cast< ::google::protobuf::uint8>(8u /* 8 & 0xFF */)) { DO_((::google::protobuf::internal::WireFormatLite::ReadPrimitive< bool, ::google::protobuf::internal::WireFormatLite::TYPE_BOOL>( @@ -1949,12 +2037,11 @@ bool BoolValue::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -1979,6 +2066,10 @@ void BoolValue::SerializeWithCachedSizes( ::google::protobuf::internal::WireFormatLite::WriteBool(1, this->value(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.BoolValue) } @@ -1993,6 +2084,10 @@ void BoolValue::SerializeWithCachedSizes( target = ::google::protobuf::internal::WireFormatLite::WriteBoolToArray(1, this->value(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.BoolValue) return target; } @@ -2001,6 +2096,11 @@ size_t BoolValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.BoolValue) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // bool value = 1; if (this->value() != 0) { total_size += 1 + 1; @@ -2078,8 +2178,10 @@ void BoolValue::UnsafeArenaSwap(BoolValue* other) { InternalSwap(other); } void BoolValue::InternalSwap(BoolValue* other) { - std::swap(value_, other->value_); - std::swap(_cached_size_, other->_cached_size_); + using std::swap; + swap(value_, other->value_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata BoolValue::GetMetadata() const { @@ -2123,9 +2225,7 @@ StringValue::StringValue() StringValue::StringValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.StringValue) @@ -2155,6 +2255,7 @@ StringValue::~StringValue() { void StringValue::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -2189,7 +2290,12 @@ StringValue* StringValue::New(::google::protobuf::Arena* arena) const { void StringValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.StringValue) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + value_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); + _internal_metadata_.Clear(); } bool StringValue::MergePartialFromCodedStream( @@ -2205,7 +2311,7 @@ bool StringValue::MergePartialFromCodedStream( // string value = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadString( input, this->mutable_value())); DO_(::google::protobuf::internal::WireFormatLite::VerifyUtf8String( @@ -2220,12 +2326,11 @@ bool StringValue::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -2255,6 +2360,10 @@ void StringValue::SerializeWithCachedSizes( 1, this->value(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.StringValue) } @@ -2275,6 +2384,10 @@ void StringValue::SerializeWithCachedSizes( 1, this->value(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.StringValue) return target; } @@ -2283,6 +2396,11 @@ size_t StringValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.StringValue) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // string value = 1; if (this->value().size() > 0) { total_size += 1 + @@ -2362,8 +2480,10 @@ void StringValue::UnsafeArenaSwap(StringValue* other) { InternalSwap(other); } void StringValue::InternalSwap(StringValue* other) { + using std::swap; value_.Swap(&other->value_); - std::swap(_cached_size_, other->_cached_size_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata StringValue::GetMetadata() const { @@ -2387,6 +2507,14 @@ void StringValue::set_value(const ::std::string& value) { value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.StringValue.value) } +#if LANG_CXX11 +void StringValue::set_value(::std::string&& value) { + + value_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.StringValue.value) +} +#endif void StringValue::set_value(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -2460,9 +2588,7 @@ BytesValue::BytesValue() BytesValue::BytesValue(::google::protobuf::Arena* arena) : ::google::protobuf::Message(), _internal_metadata_(arena) { -#ifdef GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER protobuf_google_2fprotobuf_2fwrappers_2eproto::InitDefaults(); -#endif // GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER SharedCtor(); RegisterArenaDtor(arena); // @@protoc_insertion_point(arena_constructor:google.protobuf.BytesValue) @@ -2492,6 +2618,7 @@ BytesValue::~BytesValue() { void BytesValue::SharedDtor() { ::google::protobuf::Arena* arena = GetArenaNoVirtual(); + GOOGLE_DCHECK(arena == NULL); if (arena != NULL) { return; } @@ -2526,7 +2653,12 @@ BytesValue* BytesValue::New(::google::protobuf::Arena* arena) const { void BytesValue::Clear() { // @@protoc_insertion_point(message_clear_start:google.protobuf.BytesValue) + ::google::protobuf::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + value_.ClearToEmpty(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), GetArenaNoVirtual()); + _internal_metadata_.Clear(); } bool BytesValue::MergePartialFromCodedStream( @@ -2542,7 +2674,7 @@ bool BytesValue::MergePartialFromCodedStream( // bytes value = 1; case 1: { if (static_cast< ::google::protobuf::uint8>(tag) == - static_cast< ::google::protobuf::uint8>(10u)) { + static_cast< ::google::protobuf::uint8>(10u /* 10 & 0xFF */)) { DO_(::google::protobuf::internal::WireFormatLite::ReadBytes( input, this->mutable_value())); } else { @@ -2553,12 +2685,11 @@ bool BytesValue::MergePartialFromCodedStream( default: { handle_unusual: - if (tag == 0 || - ::google::protobuf::internal::WireFormatLite::GetTagWireType(tag) == - ::google::protobuf::internal::WireFormatLite::WIRETYPE_END_GROUP) { + if (tag == 0) { goto success; } - DO_(::google::protobuf::internal::WireFormatLite::SkipField(input, tag)); + DO_(::google::protobuf::internal::WireFormat::SkipField( + input, tag, _internal_metadata_.mutable_unknown_fields())); break; } } @@ -2584,6 +2715,10 @@ void BytesValue::SerializeWithCachedSizes( 1, this->value(), output); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + ::google::protobuf::internal::WireFormat::SerializeUnknownFields( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), output); + } // @@protoc_insertion_point(serialize_end:google.protobuf.BytesValue) } @@ -2600,6 +2735,10 @@ void BytesValue::SerializeWithCachedSizes( 1, this->value(), target); } + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + target = ::google::protobuf::internal::WireFormat::SerializeUnknownFieldsToArray( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance()), target); + } // @@protoc_insertion_point(serialize_to_array_end:google.protobuf.BytesValue) return target; } @@ -2608,6 +2747,11 @@ size_t BytesValue::ByteSizeLong() const { // @@protoc_insertion_point(message_byte_size_start:google.protobuf.BytesValue) size_t total_size = 0; + if ((_internal_metadata_.have_unknown_fields() && ::google::protobuf::internal::GetProto3PreserveUnknownsDefault())) { + total_size += + ::google::protobuf::internal::WireFormat::ComputeUnknownFieldsSize( + (::google::protobuf::internal::GetProto3PreserveUnknownsDefault() ? _internal_metadata_.unknown_fields() : _internal_metadata_.default_instance())); + } // bytes value = 1; if (this->value().size() > 0) { total_size += 1 + @@ -2687,8 +2831,10 @@ void BytesValue::UnsafeArenaSwap(BytesValue* other) { InternalSwap(other); } void BytesValue::InternalSwap(BytesValue* other) { + using std::swap; value_.Swap(&other->value_); - std::swap(_cached_size_, other->_cached_size_); + _internal_metadata_.Swap(&other->_internal_metadata_); + swap(_cached_size_, other->_cached_size_); } ::google::protobuf::Metadata BytesValue::GetMetadata() const { @@ -2712,6 +2858,14 @@ void BytesValue::set_value(const ::std::string& value) { value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.BytesValue.value) } +#if LANG_CXX11 +void BytesValue::set_value(::std::string&& value) { + + value_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.BytesValue.value) +} +#endif void BytesValue::set_value(const char* value) { GOOGLE_DCHECK(value != NULL); diff --git a/src/google/protobuf/wrappers.pb.h b/src/google/protobuf/wrappers.pb.h index 4202541b..17218aa4 100644 --- a/src/google/protobuf/wrappers.pb.h +++ b/src/google/protobuf/wrappers.pb.h @@ -72,8 +72,9 @@ struct LIBPROTOBUF_EXPORT TableStruct { static const ::google::protobuf::internal::AuxillaryParseTableField aux[]; static const ::google::protobuf::internal::ParseTable schema[]; static const ::google::protobuf::uint32 offsets[]; + static const ::google::protobuf::internal::FieldMetadata field_metadata[]; + static const ::google::protobuf::internal::SerializationTable serialization_table[]; static void InitDefaultsImpl(); - static void Shutdown(); }; void LIBPROTOBUF_EXPORT AddDescriptors(); void LIBPROTOBUF_EXPORT InitDefaults(); @@ -92,7 +93,21 @@ class LIBPROTOBUF_EXPORT DoubleValue : public ::google::protobuf::Message /* @@p CopyFrom(from); return *this; } + #if LANG_CXX11 + DoubleValue(DoubleValue&& from) noexcept + : DoubleValue() { + *this = ::std::move(from); + } + inline DoubleValue& operator=(DoubleValue&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -111,6 +126,9 @@ class LIBPROTOBUF_EXPORT DoubleValue : public ::google::protobuf::Message /* @@p void UnsafeArenaSwap(DoubleValue* other); void Swap(DoubleValue* other); + friend void swap(DoubleValue& a, DoubleValue& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -167,7 +185,7 @@ class LIBPROTOBUF_EXPORT DoubleValue : public ::google::protobuf::Message /* @@p private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; double value_; @@ -187,7 +205,21 @@ class LIBPROTOBUF_EXPORT FloatValue : public ::google::protobuf::Message /* @@pr CopyFrom(from); return *this; } + #if LANG_CXX11 + FloatValue(FloatValue&& from) noexcept + : FloatValue() { + *this = ::std::move(from); + } + inline FloatValue& operator=(FloatValue&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -206,6 +238,9 @@ class LIBPROTOBUF_EXPORT FloatValue : public ::google::protobuf::Message /* @@pr void UnsafeArenaSwap(FloatValue* other); void Swap(FloatValue* other); + friend void swap(FloatValue& a, FloatValue& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -262,7 +297,7 @@ class LIBPROTOBUF_EXPORT FloatValue : public ::google::protobuf::Message /* @@pr private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; float value_; @@ -282,7 +317,21 @@ class LIBPROTOBUF_EXPORT Int64Value : public ::google::protobuf::Message /* @@pr CopyFrom(from); return *this; } + #if LANG_CXX11 + Int64Value(Int64Value&& from) noexcept + : Int64Value() { + *this = ::std::move(from); + } + inline Int64Value& operator=(Int64Value&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -301,6 +350,9 @@ class LIBPROTOBUF_EXPORT Int64Value : public ::google::protobuf::Message /* @@pr void UnsafeArenaSwap(Int64Value* other); void Swap(Int64Value* other); + friend void swap(Int64Value& a, Int64Value& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -357,7 +409,7 @@ class LIBPROTOBUF_EXPORT Int64Value : public ::google::protobuf::Message /* @@pr private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::int64 value_; @@ -377,7 +429,21 @@ class LIBPROTOBUF_EXPORT UInt64Value : public ::google::protobuf::Message /* @@p CopyFrom(from); return *this; } + #if LANG_CXX11 + UInt64Value(UInt64Value&& from) noexcept + : UInt64Value() { + *this = ::std::move(from); + } + inline UInt64Value& operator=(UInt64Value&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -396,6 +462,9 @@ class LIBPROTOBUF_EXPORT UInt64Value : public ::google::protobuf::Message /* @@p void UnsafeArenaSwap(UInt64Value* other); void Swap(UInt64Value* other); + friend void swap(UInt64Value& a, UInt64Value& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -452,7 +521,7 @@ class LIBPROTOBUF_EXPORT UInt64Value : public ::google::protobuf::Message /* @@p private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::uint64 value_; @@ -472,7 +541,21 @@ class LIBPROTOBUF_EXPORT Int32Value : public ::google::protobuf::Message /* @@pr CopyFrom(from); return *this; } + #if LANG_CXX11 + Int32Value(Int32Value&& from) noexcept + : Int32Value() { + *this = ::std::move(from); + } + inline Int32Value& operator=(Int32Value&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -491,6 +574,9 @@ class LIBPROTOBUF_EXPORT Int32Value : public ::google::protobuf::Message /* @@pr void UnsafeArenaSwap(Int32Value* other); void Swap(Int32Value* other); + friend void swap(Int32Value& a, Int32Value& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -547,7 +633,7 @@ class LIBPROTOBUF_EXPORT Int32Value : public ::google::protobuf::Message /* @@pr private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::int32 value_; @@ -567,7 +653,21 @@ class LIBPROTOBUF_EXPORT UInt32Value : public ::google::protobuf::Message /* @@p CopyFrom(from); return *this; } + #if LANG_CXX11 + UInt32Value(UInt32Value&& from) noexcept + : UInt32Value() { + *this = ::std::move(from); + } + inline UInt32Value& operator=(UInt32Value&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -586,6 +686,9 @@ class LIBPROTOBUF_EXPORT UInt32Value : public ::google::protobuf::Message /* @@p void UnsafeArenaSwap(UInt32Value* other); void Swap(UInt32Value* other); + friend void swap(UInt32Value& a, UInt32Value& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -642,7 +745,7 @@ class LIBPROTOBUF_EXPORT UInt32Value : public ::google::protobuf::Message /* @@p private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::uint32 value_; @@ -662,7 +765,21 @@ class LIBPROTOBUF_EXPORT BoolValue : public ::google::protobuf::Message /* @@pro CopyFrom(from); return *this; } + #if LANG_CXX11 + BoolValue(BoolValue&& from) noexcept + : BoolValue() { + *this = ::std::move(from); + } + inline BoolValue& operator=(BoolValue&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -681,6 +798,9 @@ class LIBPROTOBUF_EXPORT BoolValue : public ::google::protobuf::Message /* @@pro void UnsafeArenaSwap(BoolValue* other); void Swap(BoolValue* other); + friend void swap(BoolValue& a, BoolValue& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -737,7 +857,7 @@ class LIBPROTOBUF_EXPORT BoolValue : public ::google::protobuf::Message /* @@pro private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; bool value_; @@ -757,7 +877,21 @@ class LIBPROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@p CopyFrom(from); return *this; } + #if LANG_CXX11 + StringValue(StringValue&& from) noexcept + : StringValue() { + *this = ::std::move(from); + } + inline StringValue& operator=(StringValue&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -776,6 +910,9 @@ class LIBPROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@p void UnsafeArenaSwap(StringValue* other); void Swap(StringValue* other); + friend void swap(StringValue& a, StringValue& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -827,6 +964,9 @@ class LIBPROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@p static const int kValueFieldNumber = 1; const ::std::string& value() const; void set_value(const ::std::string& value); + #if LANG_CXX11 + void set_value(::std::string&& value); + #endif void set_value(const char* value); void set_value(const char* value, size_t size); ::std::string* mutable_value(); @@ -840,7 +980,7 @@ class LIBPROTOBUF_EXPORT StringValue : public ::google::protobuf::Message /* @@p private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::internal::ArenaStringPtr value_; @@ -860,7 +1000,21 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr CopyFrom(from); return *this; } + #if LANG_CXX11 + BytesValue(BytesValue&& from) noexcept + : BytesValue() { + *this = ::std::move(from); + } + inline BytesValue& operator=(BytesValue&& from) noexcept { + if (GetArenaNoVirtual() == from.GetArenaNoVirtual()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + #endif inline ::google::protobuf::Arena* GetArena() const PROTOBUF_FINAL { return GetArenaNoVirtual(); } @@ -879,6 +1033,9 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr void UnsafeArenaSwap(BytesValue* other); void Swap(BytesValue* other); + friend void swap(BytesValue& a, BytesValue& b) { + a.Swap(&b); + } // implements Message ---------------------------------------------- @@ -930,6 +1087,9 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr static const int kValueFieldNumber = 1; const ::std::string& value() const; void set_value(const ::std::string& value); + #if LANG_CXX11 + void set_value(::std::string&& value); + #endif void set_value(const char* value); void set_value(const void* value, size_t size); ::std::string* mutable_value(); @@ -943,7 +1103,7 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr private: ::google::protobuf::internal::InternalMetadataWithArena _internal_metadata_; - friend class ::google::protobuf::Arena; + template <typename T> friend class ::google::protobuf::Arena::InternalHelper; typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; ::google::protobuf::internal::ArenaStringPtr value_; @@ -956,6 +1116,10 @@ class LIBPROTOBUF_EXPORT BytesValue : public ::google::protobuf::Message /* @@pr // =================================================================== #if !PROTOBUF_INLINE_NOT_IN_HEADERS +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ // DoubleValue // double value = 1; @@ -1097,6 +1261,14 @@ inline void StringValue::set_value(const ::std::string& value) { value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.StringValue.value) } +#if LANG_CXX11 +inline void StringValue::set_value(::std::string&& value) { + + value_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.StringValue.value) +} +#endif inline void StringValue::set_value(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -1168,6 +1340,14 @@ inline void BytesValue::set_value(const ::std::string& value) { value_.Set(&::google::protobuf::internal::GetEmptyStringAlreadyInited(), value, GetArenaNoVirtual()); // @@protoc_insertion_point(field_set:google.protobuf.BytesValue.value) } +#if LANG_CXX11 +inline void BytesValue::set_value(::std::string&& value) { + + value_.Set( + &::google::protobuf::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArenaNoVirtual()); + // @@protoc_insertion_point(field_set_rvalue:google.protobuf.BytesValue.value) +} +#endif inline void BytesValue::set_value(const char* value) { GOOGLE_DCHECK(value != NULL); @@ -1222,6 +1402,9 @@ inline void BytesValue::unsafe_arena_set_allocated_value( // @@protoc_insertion_point(field_unsafe_arena_set_allocated:google.protobuf.BytesValue.value) } +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ #endif // !PROTOBUF_INLINE_NOT_IN_HEADERS // ------------------------------------------------------------------- |